(2.3.1)--ch2-03建立单链表.pdf
《(2.3.1)--ch2-03建立单链表.pdf》由会员分享,可在线阅读,更多相关《(2.3.1)--ch2-03建立单链表.pdf(10页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、 数据结构与算法Data Structures and Algorithms建立单链表 Create a Singly Linked ListData Structures and AlgorithmsData Structures and Algorithms2CHAPTER2 Linear ListLinear List(A,B,C,D,E,F,D,H)Singly Linked List:Head Pointer HHead Pointer HStorage AddressStorage AddressData FieldData FieldPoiter FieldPoiter Fiel
2、d 1 D 43 1 D 43 7 B 13 7 B 13 13 C 1 13 C 1 19 H NULL 19 H NULL 25 F 37 25 F 37 31 A 7 31 A 7 37 G 19 37 G 19 43 E 25 43 E 253131AHBCDEFGH Data Structures and AlgorithmsData Structures and AlgorithmsData Structures and AlgorithmsData Structures and Algorithms3CHAPTER2 Linear List2.4 Chain storage of
3、 linear listsSingly Linked List:each node has only one pointer fieldA singly linked list has two fields for each nodeData Field:Pointer Field:used to store the data value of the nodeused to store the direct successor address or location of data elements Head Pointer :Pointer to the head node of the
4、linked list.Node:While storing the value of each data element in the linear list at the same time that indicates the subsequent nodesaddress(or location)information,the storage image composed of these two pieces of information is called a node.Definition of node:typedef struct Node ElemType data;str
5、uct Node *next;LNode,*LinkList;Data Structures and AlgorithmsData Structures and Algorithms4CHAPTER2 Linear List2.4 Chain storage of linear listsSingly Linked Listp=(LinkList)malloc(sizeof(LNode);Indicates the operation of applying for a storage unit of type LNodeand assigning its address to the var
6、iable p;free(p)Indicates that the space of the node pointed to by the pointer p is released.Data Structures and AlgorithmsData Structures and Algorithms5CHAPTER2 Linear List2.4 Chain storage of linear lists Create a singly linked listHead insert methodsAs points to the newly applied nodes-data=A;LsA
7、Insert the first node:Insert a node:LAsB:Starting from an empty list,repeatedly read in the data to generate new nodes to store the read data in the data field of the new node,and then insert the new node after the header node of the current linked list until the end of reading is marked.s-next=L-ne
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 2.3 ch2 03 建立 单链表
限制150内