# 创建单向链表
/** 创建节点与链表 两种方式创建 头插入与尾插入 **/
function Node(data,next){
this.data = data;
this.next = next
}
function NodeList(node){
this.next = node;
this.length = 0
}
//头节点插入
function insertNodeHead(num){
var list = new NodeList(null);
for(var i = 0;i<num;i++){
var node = new Node(Math.ceil(Math.random()*100),null)
node.next = list.next;
list.next = node;
list.length++
}
}
//尾节点插入
function insertNodeTail(num){
var list = new NodeList(null);
var temp = list
for(var i=0;i<num;i++){
var node = new Node(Math.ceil(Math.random()*100),null)
temp.next = node
temp = node
list.length++
}
}
// 删除
function delNodeTail(num){
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
← 数据结构与算法