問題敘述
請你設計一個堆疊操作模擬程式,可提供插入(push)、取出(pop)、查詢(retrieve)、
檢查堆疊是否為滿(isfull)、檢查堆疊是否為空(isempty)等操作。
你的程式應該利用陣列來實作堆疊,並將各項功能寫成函數。
--------
條件限制
1.堆疊最多能儲存10筆資料。
2.當堆疊的內容改變時,請將堆疊的內容顯示出來。
3.當插入或取出、查詢資料時,須考慮堆疊為滿(isfull)或空(isempty)的情形。
4.請提供選單說明供使用者操作
eg.
****** 選單 ********
1. 插入資料
2. 取出資料
3. 查詢資料
4. 顯示堆疊內所有資料
5. 檢查堆疊是否為滿
6. 檢查堆疊是否為空
7. 離開
********************
輸入選項=>
--------------
輸入格式
無檔案輸入,由鍵盤輸入資料。
--------------
輸出格式
無檔案輸出,由營幕輸出資料。
---------------
輸入範例
略
----------
輸出範例
略
void push(int stack [],int &top,int value){
stack[top]=value;
top++;
}
int pop(int stack[],int &top){
//put your code here...
}
int retrieve(int stack[],int top){
return stack[top-1];
}
int isfull(int stack[],int size,int top){
//put your code here....
}
int isempty(int stack[],int top){
if(top==0)
return 1;
else
return 0;
}
int main(){
const int SIZE 10;
int stack[SIZE],top=0;
/*
put your code here....
*/
}