-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path双链表.cpp
48 lines (45 loc) · 857 Bytes
/
双链表.cpp
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
40
41
42
43
44
45
46
47
48
//
// Created by 不死鸟Anka on 2019-07-29.
//
//#include "双链表.h"
struct node {
int data;
node *pre, *next;
};
node *head, *p, *q, *r;
void insert(node *head, int i, int x) {
node *s, *p;
int j;
s = new node;
s->data = x;
p = head;
j = 0;
while ((p->next != NULL) && (j < 1)) {
p = p->next;
j = j + 1;
}
if (p == NULL) {
cout << "no this position! ";
} else {
s->pre = p->pre;
p->pre->next = s;
s->next = p;
p->pre = s;
}
}
void delete_(node *head, int i) {
int j;
node *p;
p = head;
j = 0;
while ((p->next != NULL) && (j < i)) {
p = p->next;
j = j + 1;
}
if (p == NULL) {
cout << "no this position! ";
} else {
p->pre->next = p->next;
p->next->pre = p->pre;
}
}