2023年4月18日发(作者:篆刻欣赏)数据结构与算法分析c语⾔英⽂版pdf,数据结构与算法分析C语
⾔英⽂版.ppt
数据结构与算法分析C语⾔英⽂版.ppt
* CHAPTER 3 Lists, Stacks, and Queues 1 Abstract Data Type 洛神赋图的作者
(ADT) 【Definition】Data Type = { Objects } ? { Operations }
〖Example〗 int = { 0, ?1, ?2, ? ? ?, INT_MAX, INT_MIN } ? { ?, ?, ?, ?, ?, ? ? ? } 【Defin关于风的诗
ition】An Abstract Data Type (ADT) is a
data type that is organized in such a way that the specification on the objects and specification of the operations on the
objects are parated from the reprentation of the objects and the implementation on the operations. 2 The List ADT
Objects: ( item0, item1, , itemN?1 ) Operations: ? Finding the length, N, of a list. ? Printing all the items in a list. ? Making
an empty list. ? Finding the k-th item from a list, 0 ? k < N. ? Inrting a new item after the k-th item of a list, 0 ? k < N. ?
Deleting an item from a list. ? Finding next of the current item from a list. ? Finding previous of the current item from a list.
ADT: Why after 1. Simple Array implementation of Lists 2 The List ADT array[ i ] = itemi MaxSize has to be estimated.
Address Content array+i itemi array+i+1 itemi+1 …… …… …… …… Sequential mapping ? Find_Kth takes O(1) time. ?
Inrtion and Deletion not only take O(N) time, but also involve a lot of data movements which takes time. 2 The List ADT
2. Linked Lists Address Data Pointer 0010 0011 0110 1011 SUN QIAN ZHAO LI 1011 0010 0011 NULL Head pointer ptr
= 0110 ZHAO QIAN刘安琪
SUN LI ptr NULL Initialization: typedef struct list_node *list_ptr; typedef struct list_node { char data [ 4 ]
; list_ptr next ; } ; list_ptr ptr ; To link ‘ZHAO’ and ‘QIAN’: list_ptr N1, N2 ; 党员鉴定评语
N1 = (list_ptr)mall汉普森英语
oc(sizeof(struct list_node));
N2 = (list_ptr)malloc(sizeof(struct list_node)); N1->data = ‘ZHAO’ ; N2->data = ‘QIAN’ ; N1->next = N2 ; N2->next =
NULL ; ptr = N1 ; ZHAO QIAN ptr NULL Locations of the nodes may change on different runs. 2 The List痛苦的近义词
ADT a1 ptr
NULL ai ai+1 an ... ... Inrtion node b temp ? temp->next =