国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網 會員登陸 & 注冊

數據結構順序棧的代碼實現2

2023-08-05 23:45 作者:愛編程的飆塵  | 我要投稿

#include <iostream>


//Stack

#define maxLen 100


using namespace std;


typedef struct elemType {

int elemNo;

string elemName;

}elemType;


typedef struct sqStack {

elemType data[maxLen];

int top;

}sqStack;


void initStack(sqStack &st){

cout<<endl<<"初始化&清除成功!"<<endl;

st.top = -1;

}



elemType getTop(sqStack &st) {//獲取棧頂

elemType t;

if(st.top > -1){

cout<<"棧頂元素為:\n";

cout<<st.data[st.top].elemNo<<endl;

t = st.data[st.top];

}

else {

cout<<"當前為空棧!"<<endl;

}

return t;


}


void getLength(sqStack st){

for(int i = 0; i <= st.top; i++){

cout<<endl<<st.data[i].elemNo<<endl;

}

cout<<"當前棧內元素個數為:"<<st.top+1<<endl;

}


void push(sqStack &st, elemType elem) {//入棧

if(st.top<maxLen-1){

elem.elemNo=st.top+1;

st.data[++st.top] = elem;

cout<<"入棧成功!"<<endl;

}

else cout<<"當前棧已滿??!"<<endl;

}


elemType pop(sqStack &st) {//出棧

elemType elem;

if(st.top>-1){

cout<<"出棧元素為:\n";

cout<<st.data[st.top].elemNo<<endl;

elem = st.data[st.top--];

}

else cout<<"當前為空棧!"<<endl;

return elem;

}


elemType setAndGetEmem(int elemNo, string elemName) {

elemType elem;

elem.elemNo = elemNo;

elem.elemName = elemName;

return elem;

}


void menu (){

cout<<endl<<"\n1.初始化棧\n2.入棧\n3.出棧\n4.獲取棧頂元素\n5.獲取棧長度\n6.退出"<<endl;

cout<<"請輸入選項: "<<endl;

}


int main() {

sqStack st; //聲明變量

while(1){

menu();

int choice = 1;

cin>>choice;

switch(choice){

case 1:initStack(st);//初始化

break;

case 2:push(st, setAndGetEmem(1, "test")); //入棧

break;

case 3:pop(st); //出棧

break;

case 4:getTop(st); //改獲取棧頂元素

break;

case 5:getLength(st); //改獲取棧頂元素

break;

case 6:cout<<"已退出?。?#34;;return 0;

break;

default:cout<<"輸入有誤!"<<endl;

}

}

return 0;

}

數據結構順序棧的代碼實現2的評論 (共 條)

分享到微博請遵守國家法律
台东市| 白朗县| 双辽市| 西和县| 武川县| 法库县| 阿城市| 肇源县| 清原| 贞丰县| 新安县| 固镇县| 昌黎县| 平安县| 万州区| 武宁县| 正蓝旗| 拉萨市| 乐山市| 通河县| 黄陵县| 虹口区| 斗六市| 武城县| 高雄县| 军事| 桂平市| 崇明县| 綦江县| 宁河县| 略阳县| 壶关县| 城口县| 怀来县| 老河口市| 育儿| 萍乡市| 高州市| 施甸县| 正宁县| 陵水|