复制代码
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72#include<stdio.h> #include<stdlib.h> typedef int ElemType; typedef struct LNode { ElemType data; struct LNode *next; }LNode,*LinkList; LinkList listTailInsert(LinkList &L) { ElemType x; LNode *s,*r; L = (LinkList)malloc(sizeof(LNode)); r = L; scanf("%d",&x); while(x!=9999) { s = (LNode*)malloc(sizeof(LNode)); s->data = x; r->next = s; r = s; scanf("%d",&x); } r->next = L; return L; } //循环单链表删除第i位元素,并存储到x中 bool deleteElem(LinkList &L,int i,ElemType &x) { LNode *p = L; LNode *s; int j = 0; while(p && j<i-1) { p = p->next; ++j; } if(p && j==i-1) { s = p->next; p->next = s->next; x = s->data; free(s); return true; } else return false; } void printList(LinkList L) { LNode *p = L->next; while(p!=L) { printf("%d ",p->data); p = p->next; } printf("n"); } void main() { LinkList L; ElemType x; listTailInsert(L); printList(L); printf("删除第2位元素,并将其保存到x中:n"); deleteElem(L,2,x); printList(L); printf("x = %dn",x); }
最后
以上就是眯眯眼乌龟最近收集整理的关于循环单链表-删除元素的全部内容,更多相关循环单链表-删除元素内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复