- 2
- 0
- 约1.04万字
- 约 51页
- 2017-07-03 发布于湖北
- 举报
DS2数据结构课件概要1
Deleting from the front of the list is a special case, because it changes the start of the list; careless coding will lose the list; The wrong code: free(L); The right one: p=L; L=L-next; free(p); A1 A2 A3 A4 ^ L × p A1 A2 A3 A4 ^ p q A third problem concerns deletion in general. Although the pointers moves above are simple, the deletion algorithm requires us to keep track of the cell before the one that we want to delete. Improve our linked list It turns out that one simple change solves all problems. We will keep a sentinel node, which is sometimes referred to as a header or dummy node. … header A2 A3 AN ^ L 2.4 Circularly Linked List A popular convention is to have the last cell keep a pointer back to the first. This can be done with or without a header( if the header is present, the last cell points to it.) … header A1 A2 AN L Creation of Linked List Method one: Inserting nodes into the head of the empty linked list. … header A1 A2 AN ^ s X L LinkList Creat_LinkList1( ) { LinkList L=NULL; LNode *s; int x; scanf(“%d”,x); while(x!=flag) { s=(LNode *)malloc(sizeof(LNode)); s-data=x; s-next=L; L=s; scanf(“%d”,x); } return L; } Creation of Linked List Inserting nodes into the tail of the linked list. … header A1 A2 AN ^ L s X ^ r LinkList Creat_LinkList( ) { LinkList L, s, r; int x; L=(LNode *)malloc(sizeof(LNode)); L-next=NULL; r=L; scanf(“%d”,x); while(x!=flag) { s=(LNode *)malloc(sizeof(LNode)); s-data=x; s-next=r-next; r-next=s; r=r-next; scanf(“%d”,x); } return L; } (2)Get the length of linked list int Length_LinkList1(LinkList L) { LNode *p=L-next; int j=0; while(p) { p=p-next; j++; } return j; } (3)Search in the linked list by number(Method1) LNode *Get_LinkList(LinkList L,int i)
您可能关注的文档
最近下载
- 2026年春季教科版三年级科学下册教学计划及进度表(新版本).docx VIP
- 14.赵海林-北斗云高精度打桩导航定位的副本-20201012-2[1].pptx VIP
- (2026 春新版)二年级科学下册教学计划及进度表.docx VIP
- 重症患者的早期康复课件.pptx VIP
- 2022年新高考全国Ⅱ卷英语真题(原卷版).pdf VIP
- 2026春新版大象版科学三年级下册教学计划.pdf VIP
- 2024年江苏省中考地理试题卷(含答案解析).docx
- 小学数学六年级上册思维拓展精选练习题.docx VIP
- 北斗云 DZ502 打桩放线导航仪 快速操作安装手册说明书.pdf VIP
- 美国机械学会标准ASME B16.51-2013 Copper and Copper Alloy Press-Connect Pressure Fittings.pdf VIP
原创力文档

文档评论(0)