《DATA STRUCTRUES A Psuedocode Approach with C++》Chaper 3. Linked List Learn Note

3-1 LINEAR LIST CONCEPTLinear lists can be divided into two categories: general and restricted.In a general list, data can be inserted and deleted anywhere and there are no restrictions on the operations that can be used to process the list. Such as the random list, ordered list.In a restricted list, data can only be added or deleted at the ends of the structure and processing is restricted to op... Read More

[LeetCode]Remove Nth Node From End of List

原题Given a linked list, remove the n-th node from the end of list and return its head.ExampleGiven linked list: 1->2->3->4->5, and n = 2.After removing the second node from the end, the linked list becomes 1->2->3->5.NoteGiven n will always be valid.Follow upCould you do this in one pass思路首先,明确题意。题目给出了一个只有后继(successor),没有前驱(predecessor)的一个单向链表。要求删除倒数第n个节点。那么,思路自然会想到的就是在一次遍历就搞定题目要求。所以,我们自然要在遍历的过程中保存一... Read More

LeetCode OJ Algorithm – reverse linked list ii (medium)

原题Reverse a linked list from position m to n. Do it in-place and in one-pass.For exampleGiven 1->2->3->4->5->NULL, m = 2 and n = 4return 1->4->3-&gNoteGiven m, n satisfy the following condition1 ≤ m ≤ n ≤ length of list.地址https://leetcode.com/problems/reverse-linked-list-ii程序范例[code lang="cpp"/** Definition for singly-linked list.* struct ListNode * int val;* ListNode *next;* ... Read More


上一篇《数据结构与算法(一),概述》中介绍了数据结构的一些基本概念,并分别举例说明了算法的时间复杂度和空间复杂度的求解方法。这一篇主要介绍线性表。本节内容一、基本概念二、顺序表三、链表1、单向链表2、单向循环链表3、双向链表4、静态链表一、基本概念线性表是具有零个或多个数据元素的有限序列。线性表中数据元素之间的关系是一对一的关系,即除了第一个和最后一个数据元素之外,其它数据元素都是首尾相接的。线性表的基本特征第一个数据元素没有前驱元素;最后一个数据元素没有后继元素;其余每个数据元素只有一个前驱元素和一个后继元素。抽象数据类型线性表一般包括插入、删除、查找等基本操作。其基于泛型的API接口代码如下[code lang="java"public interface List<//线性表的大小int size();//判断线性表是否为空boolean isEmpty();void clear();... Read More