#include
#include
#define maxlistsize 100 //預設的儲存空間最大容量
using namespace std;
typedef string elemtype;
typedef structstack;
void initstack(stack &s);
void destroystack(stack &s);
void push(stack &s);
void pop(stack &s);
void gettop(stack s);
void stacklength(stack s);
void stackempty(stack s);
void initstack (stack &s)
void push(stack &s)
if (s.top == s.stacksize)
cout << "請輸入壓入棧的元素個數(元素個數必須小於或等於" << s.stacksize - s.top << "):";
cin >> n;
cout << "請輸入壓入棧的元素:";
for(j = 0; j < n; j++)
system("pause");
}void pop(stack &s)
if (s.top == 0)
cout << "請輸入出棧的元素個數(出棧元素個數應小於或等於" << s.top << "):";
cin >> n;
cout << "出棧的元素為:";
for(j = 0; j < n; j++)
cout << endl;
system("pause");
}void gettop(stack s)
if (s.top == 0)
e = *(s.base + s.top-1); // 返回非空棧中棧頂元素
cout << "棧頂元素為:" << e << endl;
system("pause");
}void stackempty(stack s)
if(s.top == 0)
cout << "該順序棧為空棧" << endl;
else
cout << "該順序棧不為空棧" << endl;
system("pause");
}void stacklength(stack s)
// 返回s的元素個數,即棧的長度
cout << "棧長為:" << s.top << endl;
system("pause");
}void destroystack(stack &s)
delete s.base;
s.top = 0;
s.stacksize = 0;
cout << "棧已銷毀" << endl;
system("pause");
}
C 資料結構 棧之順序棧
棧 stack 是一種只允許在一端進行插入或刪除操作的線性表。棧頂 top 是允許進行插入刪除的一端。棧底 bottom 是固定不允許插入刪除的一端。棧的操作特性概括為後進先出 last in first out,lifo 相關知識 c 結構體 c 指標 c 引用 線性表之順序表 假定線性表的元素型...
資料結構之順序棧
棧的順序儲存結構用一組位址連續的儲存單元 陣列,依次存放自棧底到棧頂的資料元素。最簡單的一種棧的寫法如下 define maxsize 100 int stack maxsize int top 棧頂位置 void initstack void clearstack int gettop int e...
資料結構之順序棧
前面我們學習了順序鍊錶,我們可能會覺得順序鍊錶有啥用呢?基本都是要被淘汰了用法。呵呵,俗話說 存在的即是合理的。下面我來炫炫它的用法,請睜大你的眼睛,下面是見證奇蹟的時刻。第六個例子,順序棧的實現 標頭檔案要包含兩部分,乙個是我們先前實現的順序表,不清楚,出門右轉,看前面的文章 標頭檔案 ifnde...