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

158 lines
5.3 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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