Posted on 2009-08-20 22:21
chenweiwei 阅读(265)
评论(0) 编辑 收藏 引用
1
2 struct Node
3 {
4 int data;
5 struct Node *next;
6 };
7
8 int InitLink(Node *h)
9 {
10 int i;
11 Node *p, *q;
12 p = new Node;
13 p = h;
14 for (i = 1; i <= 10; ++i)
15 {
16 q = new Node;
17 q ->data = i;
18 p ->next = q;
19 p = q;
20 }
21 p ->next = NULL;
22 return 0;
23 };
24
25 int ReverseLink(Node *head)
26 {
27 Node *p, *q, *cur;
28
29 p = head ->next;
30 cur = q = p;
31 cur = cur ->next;
32 p = p ->next->next;
33 q->next = NULL;
34
35 while (p != NULL)
36 {
37 cur ->next = q;
38 q = cur;
39 cur = p;
40 p = p->next;
41 }
42 cur ->next = q;
43 head ->next = cur;
44 return 0;
45 }
46
47 int main()
48 {
49 Node *head;
50 head = new Node;
51 InitLink(head);
52 ReverseLink(head);
53 return 0;
54 }