抽象資料型別(abstract data type,adt)是電腦科學中具有類似行為的特定類別的資料結構的數學模型;或者具有類似語義的一種或多種程式語言的資料型別。抽象資料型別是間接定義的,通過其上的可執行的操作以及這些操作的效果的數學約束(與可能的代價)。——維基百科
#ifndef stack_h_included
#define stack_h_included
typedef
enum status
status;
typedef
int elemtype;
typedef
struct stacknode
stacknode,
*linkstackptr;
typedef
struct linkstack
linkstack;
// linkstack.
status initlstack
(linkstack *s)
;// 初始化棧
status isemptylstack
(linkstack *s)
;// 判斷棧是否為空
status gettoplstack
(linkstack *s,elemtype *e)
;// 得到棧頂元素
status clearlstack
(linkstack *s)
;// 清空棧
status destroylstack
(linkstack *s)
;// 銷毀棧
status lstacklength
(linkstack *s,
int*length)
;// 檢測棧長度
status pushlstack
(linkstack *s,elemtype data)
;// 入棧
status poplstack
(linkstack *s,elemtype *data)
;// 出棧
status printstack
(linkstack * s)
;// 實時列印鏈棧
intinputnumber()
;// 輸入整數檢測
#endif
#include
#include
#include
"linkstack.h"
intmain()
else
break
;case3:
if(flag ==1)
else
break
;case4:
if(flag ==1)
else
break
;case5:
if(flag ==1)
else
break
;case6:
break
;case7:
if(flag ==1)
else
break
;case8:
if(flag ==1)
else
break
;case9:
printf
("\nbyebye~");
exit(0
);break
;default
:printf
("no such option.\n");
}system
("pause");
}return0;
}
#include
#include
#include
"linkstack.h"
// linkstack.
stacknode *bottom =
null
;// linkstack.
status initlstack
(linkstack *s)
status isemptylstack
(linkstack *s)
printf
("not empty.\n");
return error;
}status gettoplstack
(linkstack *s, elemtype *e)
*e = s->top->data;
printf
("the top element is %d.\n"
,*e)
;return success;
}status clearlstack
(linkstack *s)
printf
("successfully clear the stack.\n");
return success;
}status destroylstack
(linkstack *s)
printf
("successfully destroy the stack.\n");
return success;
}status lstacklength
(linkstack *s,
int*length)
*length = s->count;
printf
("the length of the stack is %d.\n"
,*length)
;return success;
}status pushlstack
(linkstack *s, elemtype data)
status poplstack
(linkstack *s, elemtype *data)
else
}printf
("successfully pop %d out the stack.\n"
,*data)
;return success;}}
// 實時列印鏈棧
status printstack
(linkstack * s)
else
if(s->count ==0)
for(p = bottom->next; p; p = p->next)
printf
("\n");
return success;
}// 輸入整數檢測
資料結構 棧ADT
棧 stack 是限定僅在表尾插入和刪除操作的線性表 允許插入和刪除的一端稱為棧頂 top 另一端稱為棧底 bottom 我們可以模擬手槍彈夾,瀏覽器的後退和前進等等都是棧 棧的插入操作,稱為進棧,也稱壓棧 入棧 push 棧的刪除操作,稱為出棧,也稱為彈棧 pop 棧本身就是乙個線性表,線性表的順...
資料結構 順序棧ADT
抽象資料型別 abstract data type,adt 是電腦科學中具有類似行為的特定類別的資料結構的數學模型 或者具有類似語義的一種或多種程式語言的資料型別。抽象資料型別是間接定義的,通過其上的可執行的操作以及這些操作的效果的數學約束 與可能的代價 維基百科 ifndef stack h in...
資料結構 回顧棧ADT和隊ADT
1.簡單的說,棧就是只在乙個位置上進行插入和刪除操作的表,而這個特殊的位置就是表的末端,但這卻不被成為棧的末端,而是頂 top 2.棧的基本操作時進棧和出棧,英文名分別是push和pop,分別相當於插入和刪除。切記對空棧進行pop和top操作在棧adt被認為是錯誤的,而如果push在空間之外進行操作...