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

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

棧 — 順序棧

2019-11-09 19:30:44
字體:
供稿:網(wǎng)友

代碼

/* function:sequence stack created by : xilong date: 2017.2.9*/#include "iostream"#include <stdlib.h>#include <math.h>using namespace std;#define OK 1#define ERROR 0#define TRUE 1#define FALSE 0#define STACK_SIZE 20#define STACK_INCREMENT 10typedef int Status;typedef int Elemtype;typedef struct{ Elemtype *base; Elemtype *top; int stackSize;} sqStack;/* initialize the stack*/void Init_Stack(sqStack *s){ s->base = (Elemtype *)malloc(STACK_SIZE *sizeof(Elemtype)); if (!s->base) { exit(0); } s->top = s->base; s->stackSize = STACK_SIZE;}/* push*/void Push_Stack(sqStack *s, Elemtype e){ if (s->top - s->base >= s->stackSize) { s->base = (Elemtype *)realloc(s->base, (s->stackSize + STACK_INCREMENT) * sizeof(Elemtype)); if (!s->base) { exit(0); } s->top = s->base + s->stackSize; s->stackSize = s->stackSize + STACK_INCREMENT; } *(s->top) = e; s->top++;}/* Pop*/void Pop_Stack(sqStack *s, Elemtype *e){ if (s->top == s->base) { exit(0); } *e = *--(s->top);}/* destory the stack*/Status Destory_Stack(sqStack *s){ int i; for (i = 0; i < s->stackSize; i++) { free(s->base); s->base++; } s->base = s->top = NULL; s->stackSize = 0; return OK;}/* the length of the stack*/int Length_Stack(sqStack *s){ return(s->top - s->base);}void main(){ sqStack s; Elemtype e; int len, i; Init_Stack(&s); Push_Stack(&s, 1); Push_Stack(&s, 2); Push_Stack(&s, 3); Push_Stack(&s, 4); Push_Stack(&s, 5); Push_Stack(&s, 6); cout << "the length of the stack currently:"; cout << Length_Stack(&s) << endl; len = Length_Stack(&s); cout << "出棧順序?yàn)椋?; for (i = 0; i < len; i++) { Pop_Stack(&s, &e); cout << e << " "; } cout << endl; //Destory_Stack(&s); system("pause");}

截圖

這里寫圖片描述


發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 尚义县| 甘肃省| 寻乌县| 信宜市| 平度市| 普格县| 绩溪县| 奉化市| 沙洋县| 东莞市| 卢氏县| 丹东市| 石城县| 天长市| 鲁山县| 龙南县| 婺源县| 会昌县| 芜湖市| 旬邑县| 信宜市| 且末县| 东光县| 梅河口市| 辽宁省| 鹿泉市| 旅游| 溧水县| 夹江县| 翁牛特旗| 荆门市| 乳山市| 商城县| 安达市| 衡南县| 凤山市| 兴义市| 大同市| 阿鲁科尔沁旗| 巴青县| 柳林县|