heylinart

导航

Linked List

链表是线性表的一种。线性表是最基本,最简单也是最常见的一种数据结构。
线性表中数据元素之间的关系是一对一的关系,除了第一个和最后一个数据元素外,其他数据元素都是首尾相接的。

线性表有两种存储方式,一种是顺序存储结果,另一种是链式存储结构。数组就是一种最为常见的典型的顺序存储结构。
相反,链式存储结构就是两个相邻的元素在内存中可能不是相邻的,每一个元素都有一个指针域,指针域一般是存储着
到下一个元素的指针。这种存储方式的优点是插入和删除的时间复杂度为O(1),不会浪费太多内存,添加元素的时候才会申请内存,删除元素的时候会释放内存。
缺点是访问的时间复杂度最坏为O(n).
顺序表的特性是随机读取,也就是访问一个元素的时间复杂度是O(1),链式表的特性是插入和删除的时间复杂度为O(1)。
链表就是链式存储的线性表。根据指针域的不同,链表分为单向链表,双向链表,循环链表等。


Array VS linked lists:

Arrays are great for storing things in a certain order, but they have drawbacks.
The capacity of the array must be fixed when it is created, and insertions and deletions at interior positions of an array can be time consuming if many elements
must be shifted.

An important property of a linked list is that it does not have a predetermined fixed size;it use space proportional to its current number of elements.When using a singly linked list, we can easily insert an element at the head of the list.

基本操作:

插入

删除

遍历

反向遍历

posted on 2017-06-01 11:22  heylinart  阅读(195)  评论(0编辑  收藏  举报