1. 程式人生 > 遊戲 >《黑客帝國:覺醒》PC版展示:交通高峰期藝術攝影

《黑客帝國:覺醒》PC版展示:交通高峰期藝術攝影

順序棧:

#include <iostream>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
typedef char Element;
#define maxsize 10
// 順序棧
typedef struct {
    Element c[maxsize];
    int top;  // 棧頂指標

}Sqstack;

//初始化棧
void initStack(Sqstack &s){
    s.top=-1;
}
//判斷是否為空
bool SqstackEmpty(Sqstack s){
    
if(s.top==-1) return true; else return false; } //進棧 bool pushStack(Sqstack &s,Element c){ if(s.top==maxsize-1){ return false; } s.c[++s.top]=c; //printf("top:%d",s.top); return true; } //出棧 bool popStack(Sqstack &s){ if
(s.top==-1){ //printf("棧為空!"); cout<<"棧為空"<<endl; return false; } s.top=s.top-1; return true; } //遍歷棧 void getStack(Sqstack s){ int i=0; for(i;i<=s.top;i++){ printf("%c ",s.c[i]); } } int main() { Sqstack s; initStack(s); //初始化棧
int a=pushStack(s,'A'); a=pushStack(s,'B'); a=pushStack(s,'C'); a=pushStack(s,'D'); a=pushStack(s,'E'); getStack(s); printf("\n"); if(!SqstackEmpty(s)){ //若棧不為空 int b =popStack(s); //出棧 getStack(s); //遍歷 } }