C語言:反向輸出棧方法實(shí)現(xiàn)-創(chuàng)新互聯(lián)

#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("請(qǐng)輸入入棧的元素個(gè)數(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)建一個(gè)空棧,棧頂下標(biāo)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("棧滿,不能進(jìn)棧操作!");
		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)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機(jī)房具備T級(jí)流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級(jí)服務(wù)器適合批量采購,新人活動(dòng)首月15元起,快前往官網(wǎng)查看詳情吧

創(chuàng)新互聯(lián)公司專注于皮山網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠為您提供皮山營銷型網(wǎng)站建設(shè),皮山網(wǎng)站制作、皮山網(wǎng)頁設(shè)計(jì)、皮山網(wǎng)站官網(wǎng)定制、微信小程序開發(fā)服務(wù),打造皮山網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供皮山網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。

網(wǎng)站題目:C語言:反向輸出棧方法實(shí)現(xiàn)-創(chuàng)新互聯(lián)
網(wǎng)站地址:http://muchs.cn/article48/dcheep.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供手機(jī)網(wǎng)站建設(shè)、靜態(tài)網(wǎng)站、服務(wù)器托管、Google云服務(wù)器、網(wǎng)站改版

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)頁設(shè)計(jì)公司