algorithm-base/animation-simulation/数据结构和算法/关于链表的那些事.md

151 lines
5.4 KiB
Java
Raw Normal View History

2021-03-20 07:58:25 +00:00
#
2021-07-23 15:44:19 +00:00
> **[tan45du_one](https://raw.githubusercontent.com/tan45du/tan45du.github.io/master/个人微信.15egrcgqd94w.jpg)** ,备注 github + 题目 + 问题 向我反馈
2021-03-20 08:30:29 +00:00
>
>
>
2021-07-23 15:44:19 +00:00
> <u>[****](https://raw.githubusercontent.com/tan45du/test/master/微信图片_20210320152235.2pthdebvh1c0.png)</u> 两个平台同步,想要和题友一起刷题,互相监督的同学,可以在我的小屋点击<u>[**刷题小队**](https://raw.githubusercontent.com/tan45du/test/master/微信图片_20210320152235.2pthdebvh1c0.png)</u>进入。
2021-03-20 08:30:29 +00:00
2021-03-20 07:58:25 +00:00
1.
2.
3.
4.
5.
6.
7.
8.
###
> nullnode
2021-07-23 15:44:19 +00:00
线线线 null
2021-03-20 07:58:25 +00:00
###
便
-
-
-
####
:
2021-03-21 04:51:52 +00:00
![](https://img-blog.csdnimg.cn/20210321125110539.png)
2021-03-20 07:58:25 +00:00
####
:
![](https://cdn.jsdelivr.net/gh/tan45du/photobed@master/photo/双链表.3cw4hra1g3q0.png)
2021-07-23 15:44:19 +00:00
####
2021-03-20 07:58:25 +00:00
2021-07-23 15:44:19 +00:00
leetcode61
2021-03-20 07:58:25 +00:00
###
2021-07-23 15:44:19 +00:00
java
2021-03-20 07:58:25 +00:00
```java
private class Node {
Item item;
Node next;
}
```
2021-07-23 15:44:19 +00:00
one,two,three
2021-03-20 07:58:25 +00:00
```java
Node first = new Node();
Node second = new Node();
Node third = new Node();
```
2021-07-23 15:44:19 +00:00
item
2021-03-20 07:58:25 +00:00
```java
first.item = "one";
second.item = "two";
third.item = "three";
```
2021-07-23 15:44:19 +00:00
next
2021-03-20 07:58:25 +00:00
```java
first.next = second;
second.next = third;
```
2021-07-23 15:44:19 +00:00
third next null
2021-03-20 07:58:25 +00:00
###
![image-20201101153659912](https://cdn.jsdelivr.net/gh/tan45du/photobed@master/photo/image-20201101153659912.9neaap4ogtc.png)
###
2021-07-23 15:44:19 +00:00
使 while for
2021-03-20 07:58:25 +00:00
for:
```java
for (Node x = first; x != null; x = x.next) {
//处理x.item
}
```
while:
```
Node x = first;
while (x!=null) {
//处理x.item
x = x.next;
}
```
###
####
![image-20201101155937520](https://cdn.jsdelivr.net/gh/tan45du/photobed@master/photo/image-20201101155937520.my13cevp2cg.png)
####
2021-07-23 15:44:19 +00:00
B
2021-03-20 07:58:25 +00:00
![image-20201101155003257](https://cdn.jsdelivr.net/gh/tan45du/photobed@master/photo/image-20201101155003257.4onlntrwj2i0.png)
2021-07-23 15:44:19 +00:00
A next C
2021-03-20 07:58:25 +00:00
2021-07-23 15:44:19 +00:00
B java C++,
2021-03-20 07:58:25 +00:00
2021-07-23 15:44:19 +00:00
O(1)
2021-03-20 07:58:25 +00:00
| | /() | | |
| ---- | ------------------------- | ------------------ | ------------ |
| | O(n) | O(1) | |
| | O(1) | O(n) | |