#include#include #define IS_FULL(ptr) (!(ptr)) typedef int T; typedef struct node { T Key; T Data; struct node* link; }Node; Node* BuildList() { Node* p; Node* r = NULL; Node* first = NULL; int i; for (i = 0; i < 10;i++) { p = (Node*)malloc(sizeof(Node)); p->Key = 2 * i + 1; p->Data = 2 * i + 2; p->link = NULL; if (first != NULL) { r->link = p; } else { first = p; } r = p; } return first; } Node* SearchList(Node* first, int k) { Node* p; Node* r; int i=1; r = (Node*)malloc(sizeof(Node)); p = (Node*)malloc(sizeof(Node)); r ->link= first; p = first; if (first->Key==k) { i = 0; } while (p != NULL) { if (p->Key != k) { r = r->link; p = p->link; } else { printf("%dt%dn",p->Key,p->Data); if (i) { r->link = p->link; p->link = first; } break; } } if (p==NULL) { printf("Can't find it!n"); exit(1); } else { return p; } } void PrintList(Node* first) { printf("n the list contains: n"); for (; first; first = first->link) { printf("%dt%dn", first->Key, first->Data); } printf("nn"); } void Clear(Node** first) { Node* p; p = *first; while (*first) { p = (*first)->link; free(*first); *first = p; } } void main() { Node* lst; lst = BuildList(); PrintList(lst); lst=SearchList(lst, 9); PrintList(lst); lst = SearchList(lst, 13); PrintList(lst); lst = SearchList(lst, 11); PrintList(lst); lst = SearchList(lst, 11); PrintList(lst); lst = SearchList(lst, 11); PrintList(lst); //Clear(&lst); //PrintList(lst); }
the list contains:
1 2
3 4
5 6
7 8
9 10
11 12
13 14
15 16
17 18
19 20
9 10
the list contains:
9 10
1 2
3 4
5 6
7 8
11 12
13 14
15 16
17 18
19 20
13 14
the list contains:
13 14
9 10
1 2
3 4
5 6
7 8
11 12
15 16
17 18
19 20
11 12
the list contains:
11 12
13 14
9 10
1 2
3 4
5 6
7 8
15 16
17 18
19 20
11 12
the list contains:
11 12
13 14
9 10
1 2
3 4
5 6
7 8
15 16
17 18
19 20
11 12
the list contains:
11 12
13 14
9 10
1 2
3 4
5 6
7 8
15 16
17 18
19 20
C:C程序&C语言数据结构C语言数据结构_从入门到入坑7-15移至开头-自组织表Debug移至开头-自组织表.exe (进程 6692)已退出,代码为 0。
要在调试停止时自动关闭控制台,请启用“工具”->“选项”->“调试”->“调试停止时自动关闭控制台”。
按任意键关闭此窗口. . .
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)