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.
基本操作:
插入
删除
遍历
反向遍历
Linked List的更多相关文章
- [LeetCode] Linked List Random Node 链表随机节点
Given a singly linked list, return a random node's value from the linked list. Each node must have t ...
- [LeetCode] Plus One Linked List 链表加一运算
Given a non-negative number represented as a singly linked list of digits, plus one to the number. T ...
- [LeetCode] Odd Even Linked List 奇偶链表
Given a singly linked list, group all odd nodes together followed by the even nodes. Please note her ...
- [LeetCode] Delete Node in a Linked List 删除链表的节点
Write a function to delete a node (except the tail) in a singly linked list, given only access to th ...
- [LeetCode] Palindrome Linked List 回文链表
Given a singly linked list, determine if it is a palindrome. Follow up: Could you do it in O(n) time ...
- [LeetCode] Reverse Linked List 倒置链表
Reverse a singly linked list. click to show more hints. Hint: A linked list can be reversed either i ...
- [LeetCode] Remove Linked List Elements 移除链表元素
Remove all elements from a linked list of integers that have value val. Example Given: 1 --> 2 -- ...
- [LeetCode] Intersection of Two Linked Lists 求两个链表的交点
Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...
- [LeetCode] Linked List Cycle II 单链表中的环之二
Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Foll ...
- [LeetCode] Linked List Cycle 单链表中的环
Given a linked list, determine if it has a cycle in it. Follow up: Can you solve it without using ex ...
随机推荐
- RNA-seq流程需要进化啦!
RNA-seq流程需要进化啦! Posted on 2015年9月25日 Tophat 首次被发表已经是6年前 Cufflinks也是五年前的事情了 Star的比对速度是tophat的50倍,hisa ...
- POJ3621或洛谷2868 [USACO07DEC]观光奶牛Sightseeing Cows
一道\(0/1\)分数规划+负环 POJ原题链接 洛谷原题链接 显然是\(0/1\)分数规划问题. 二分答案,设二分值为\(mid\). 然后对二分进行判断,我们建立新图,没有点权,设当前有向边为\( ...
- The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone问题解决
从错误即可知道是时区的错误,因此只要将时区设置为你当前系统时区即可 因此使用root用户登录mysql,按照如下图所示操作即可. 把时区设置为所在地时区(即东八区的时区)后,再连接数据库就可以了
- idea窗口下方滚动条不明显设置
在使用idea时,下方的滚动条老是显示不明显,每次点击拖拽都很费劲,在网上找了很多相关设置,最后确定了一个最好的办法解决问题: Shift (上档) + 鼠标滚动,这样就可以横向翻滚了,很方便 此方 ...
- 让UI设计师崩溃的瞬间,你经历过哪些?
隔行如隔山,这句话人人耳熟能详,但其实隔行并不可怕,大家各谋其事,各尽其职,倒也互不打扰,真正可怕的是,是内行还要受外行指点江山,而最难的部分,便是那沟通.流畅的沟通,和声细语,是有如时雨之化者:无效 ...
- boost timer代码学习笔记
socket连接中需要判断超时 所以这几天看了看boost中计时器的文档和示例 一共有五个例子 从简单的同步等待到异步调用超时处理 先看第一个例子 // timer1.cpp: 定义控制台应用程序的入 ...
- maven mirror , profile , snapshot 和release
1. settings.xml 配置的mirror <mirrors> <mirror> <id>Nexus</id> <name>nexu ...
- 跟我学Spring Boot(二)Hello World
1.打开DemoApplication添加如下代码 package com.example; import org.springframework.boot.SpringApplication; im ...
- jquery ajax 全局事件
jquery的ajax方法的全部全局事件:(不管是$.ajax().$.get().$.load().$.getJSON()等都会默认触发全局事件) ajaxStart:ajax请求开始前 ajaxS ...
- sql心跳
因为interactive_timeout决定的是交互连接的时间长短,而wait_timeout决定的是非交互连接的时间长短. 问:为什么需要设置interactive_timeout wait_t ...