資料結構總複習DataStructure+.ppt
《資料結構總複習DataStructure+.ppt》由会员分享,可在线阅读,更多相关《資料結構總複習DataStructure+.ppt(53页珍藏版)》请在三一办公上搜索。
1、資料結構總複習,什麼是Data structure?,將資料群組織起來的抽象資料型態,稱為資料結構。,典型的資料結構,資料表格(Table)堆疊(stack)佇列(queue)串列(list)樹(tree)圖形(graph)table,stack,queue:可用陣列表現出來List,tree,graph:適合用指標表現出來。,堆疊(Stack),將資料依序從堆疊下面儲存起來,並視需要從堆疊的上面將資料取出的方式之資料結構,稱為堆疊。,Push,Stack,E,A,D,堆疊(Stack),【特性】:後進先出(LIFO)LIFO:last in first out。【動作】:push:儲存資料進
2、堆疊。pop:將資料從堆疊中取出。,Push 的演算法:,int top=0;/top初值為0push(n)if(topMaxSize)stacktop=n;top+;return 0;else return-1;,Pop 的演算法:,pop()if(top0)top-;k=stacktop;return k;else return-1;,佇列(queue),處理資料的方式先進先出。FIFO:First In First Out,in,佇列(queue),queue0,queue1,queue2,queueN-1,佇列(queue),現設有queue0至queuen-1共n個元素的陣列,表示佇
3、列開頭的指標設為head,表示佇列尾端的指標設為tail。取出資料:在head進行。head=head+1。儲存資料:在tail位置進行。tail=tail+1;佇列初始狀態:head=tail=0佇列為空:當head=tail時。佇列為滿:tail+1為 n 時。,佇列(queue),解決佇列使用一次就無法使用的問題:當head=tail=n時。將陣列尾端queuen-1與開頭queue0連結起來成為一個環形佇列。,鏈結串列(Linked List),鏈結串列是一種有順序的串列,Linked List的優點,它比循序的串列(sequential list,如陣列)更容易做任意資料的插入(in
4、sertions)與刪除(deletions)。在mat和cat之間加入 sat:Get a node that is currently unused;let its address be paddr.Set the data field of this node to mat.Set paddrs link field to point to the address found in the link field of the node containing cat.Set the link field of the node containing cat to point to padd
5、r.,以結構定義一個Link List,必要的宣告如下:typedef struct list_node*list_pointer;typedef struct list_node char data4;list_pointer link;list_pointer ptr=NULL;,建立一個新節點(node),產生一個新的 nodeptr=(list_pointer)malloc(sizeof(list_node);/配置一個指標空間把字串資料“bat“放入 list 中strcpy(ptr-data,“bat”);ptr-link=NULL;,Create a two-node list,
6、typedef struct list_node*list_pointer;typedef struct list_node int data;list_pointer link;list_pointer ptr=NULL;list_pointer create2()list_pointer first,second;first=(list_pointer)malloc(sizeof(list_node);second=(list_pointer)malloc(sizeof(list_node);second-link=NULL;second-data=20;first-data=10;fir
7、st-link=second;return first;,刪除節點(Deletion)from a list,void delete(list_pointer*ptr,list_pointer trail,list_pointer node)/*ptr may change,pass in the address of ptr*/*trail is the preceding node,ptr is the head of the list*/if(trail)trail-link=node-link;else*ptr=(*ptr)-link;free(node);,Linked List的應
8、用,多項式(Polynomials)表示,typedef struct poly_node*poly_pointer;typedef struct poly_node int coef;int expon;poly_pointer link;poly_pointer a,b,d;,環形linked lists,If the link field of the last node points to the first node in the list,all the nodes of a polynomial can be freed more efficiently.Circular 表示方
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 資料結構總複習 DataStructure

链接地址:https://www.31ppt.com/p-2336983.html