日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

第5周实践项目1 顺序栈建立的算法库

發布時間:2025/4/16 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 第5周实践项目1 顺序栈建立的算法库 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
main.cpp #include <stdio.h> #include "Sqstack.h" int main() {Elemtype e;SqStack *s;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)棧長度:%d\n",StackLength(s));printf("(6)從棧頂到棧底元素:");DispStack(s);printf("(7)出棧序列:");while (!StackEmpty(s)){Pop(s,e);printf("%c ",e);}printf("\n");printf("(8)棧為%s\n",(StackEmpty(s)?"空":"非空"));printf("(9)釋放棧\n");DestroyStack(s);return 0; } sqstack.h #include <stdio.h> #define MaxSize 100 typedef char Elemtype; typedef struct {Elemtype date[MaxSize];int top; }SqStack; void InitStack(SqStack *&s); void DestroyStack(SqStack *&s); //銷毀棧 bool StackEmpty(SqStack *s); //棧是否為空 int StackLength(SqStack *s); //返回棧中元素個數——棧長度 bool Push(SqStack *&s,Elemtype e); //入棧 bool Pop(SqStack *&s,Elemtype &e); //出棧 bool GetTop(SqStack *s,Elemtype &e); //取棧頂數據元素 void DispStack(SqStack *s); //輸出棧 sqstack.h #include <stdio.h> #include <malloc.h> #include "sqstack.h" void InitStack(SqStack *&s) {s=(SqStack *)malloc(sizeof(SqStack));s->top=-1; } void DestroyStack(SqStack *&s) {free(s); } int StackLength(SqStack *s) {return s->top+1; } bool StackEmpty(SqStack *s) {return s->top==-1;//在這兒s->top 用==判斷不能用= } bool Push(SqStack *&s,Elemtype e) {if(s->top==MaxSize-1)return false;//s->top++;s->date[++s->top]=e;return true; } bool Pop(SqStack *&s,Elemtype &e) {if(s->top==-1)return false;e=s->date[s->top--];//s->top--;return true; } bool GetTop(SqStack *s,Elemtype &e) {if(s->top==-1)return false;e=s->date[s->top];return true; } void DispStack(SqStack *s) {int i;for(i=s->top;i>-1;--i)printf("%c",s->date[i]);printf("\n"); }

總結

以上是生活随笔為你收集整理的第5周实践项目1 顺序栈建立的算法库的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。