国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

棧之順序棧基本操作

2019-11-11 07:09:02
字體:
來源:轉載
供稿:網友
#include <stdio.h>#include <malloc.h>#define MaxSize 100//順序棧的存儲結構typedef char ElemType;typedef struct{	ElemType data[MaxSize];	int top;					//棧頂指針} SqStack;//初始化棧void InitStack(SqStack *&s){    s=(SqStack *)malloc(sizeof(SqStack));    s->top=-1;//棧頂指針置為-1}//銷毀棧void DestroyStack(SqStack *&s){    free(s);}//判斷棧是夠為空int  StackEmpty(SqStack *s){    return (s->top==-1);}//進棧bool Push(SqStack *&s,ElemType e){    if(s->top==MaxSize-1)//判斷棧是否棧滿防止溢出        return false;    s->top++;//棧頂指針增加一    s->data[s->top]=e;    return true;}//出棧bool Pop(SqStack *&s,ElemType &e){    if(s->top==-1)//棧為空的情況,即棧下溢出        return false;    e=s->data[s->top];    s->top--;    return true;}//取棧頂元素bool GetTop(SqStack *s,ElemType &e){    if(s->top==-1)//棧為空的情況,即棧下溢出        return false;    e=s->data[s->top];    return true;}int main(){	ElemType e;	SqStack *s;	PRintf("棧s的基本運算如下:/n");	printf("  (1)初始化棧s/n");	InitStack(s);	printf("  (2)棧為%s/n",(StackEmpty(s)?"空":"非空"));	printf("  (3)依次進棧元素a,b,c,d,e/n");	Push(s,'a');	Push(s,'b');	Push(s,'c');	Push(s,'d');	Push(s,'e');	printf("  (4)棧為%s/n",(StackEmpty(s)?"空":"非空"));	printf("  (5)出棧序列:");	while (!StackEmpty(s))	{		Pop(s,e);		printf("%c ",e);	}	printf("/n");	printf("  (6)棧為%s/n",(StackEmpty(s)?"空":"非空"));	printf("  (7)釋放棧/n");	DestroyStack(s);    return 0;}

運行結果:


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 射洪县| 盈江县| 秦皇岛市| 民县| 彭山县| 永城市| 蓝田县| 庆阳市| 临邑县| 大同县| 彭阳县| 日照市| 红原县| 团风县| 合作市| 应城市| 合肥市| 页游| 乐业县| 长武县| 高陵县| 大同县| 四子王旗| 宜良县| 论坛| 宜兰市| 大同县| 杭锦后旗| 岱山县| 法库县| 沁水县| 松阳县| 永善县| 聊城市| 壶关县| 区。| 寻乌县| 申扎县| 永济市| 西青区| 龙海市|