#include#define MAXLEN 100
typedef int DataType;
typedef struct
{DataType data[MAXLEN];
int top;
}SeqStack;
void InitStack(SeqStack *S);//初始化棧
int EmptyStack(SeqStack *S);//棧空判斷函數(shù)
int FullStack(SeqStack *S);//棧滿判斷函數(shù)
int push(SeqStack *S , DataType x);//入棧操作函數(shù)
int pop(SeqStack *S , DataType *x);//出棧操作函數(shù)
int main()
{SeqStack S;
DataType x;
int flag , n;
printf("請輸入入棧的元素個數(shù):");
scanf("%d",&n);
for(int i = 0 ; i< n ; i++){scanf("%d",&x);
flag = push(&S,x);
}
// printf("入棧操作成功!\n");
flag = 0;
printf("出棧的元素為:");
for(int i = 0 ; i< n ; i++){flag = pop(&S,&x);
printf("%3d",x);
}
// printf("\n出棧操作成功!\n");
return 0;
}
void InitStack(SeqStack *S)
{//創(chuàng)建一個空棧,棧頂下標top初始化為-1
S->top = -1;
}
int EmptyStack(SeqStack *S)
{//判斷棧空函數(shù)
if(S->top==-1){return 1;
}else{return 0;
}
}
int FullStack(SeqStack *S)
{//判斷棧滿函數(shù)
if(S->top == MAXLEN-1){return 1;
}else{return 0;
}
}
int push(SeqStack *S , DataType x)
{//入棧操作函數(shù)
if(FullStack(S)){printf("棧滿,不能進棧操作!");
return 0;
}else{S->top++;
S->data[S->top] = x;
return 1;
}
}
int pop(SeqStack *S , DataType *x)
{//出棧操作函數(shù)
if(EmptyStack(S)){printf("棧空,不能出棧操作!");
return 0;
}else{*x = S->data[S->top];
S->top--;
return 1;
}
}
你是否還在尋找穩(wěn)定的海外服務器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機房具備T級流量清洗系統(tǒng)配攻擊溯源,準確流量調(diào)度確保服務器高可用性,企業(yè)級服務器適合批量采購,新人活動首月15元起,快前往官網(wǎng)查看詳情吧

網(wǎng)站題目:C語言:反向輸出棧方法實現(xiàn)-創(chuàng)新互聯(lián)
網(wǎng)站地址:http://www.chinadenli.net/article48/dcheep.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供手機網(wǎng)站建設、靜態(tài)網(wǎng)站、服務器托管、Google、云服務器、網(wǎng)站改版
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容