数据结构之 顺序栈的操作

来源:互联网 发布:mac如何打开jar文件 编辑:程序博客网 时间:2024/05/29 06:47
// 栈.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include "malloc.h"#define maxSize 100 typedef struct {int data[maxSize];int top;}SqStack;void push(SqStack &st,int x){if(st.top==maxSize-1)return;st.top++;st.data[st.top]=x;}void pop(SqStack &st,int &x){if(st.top==-1)return;x=st.data[st.top];st.top--;return;}void show(SqStack &st){if(st.top==-1)return;int x;while(st.top!=-1){pop(st,x);printf("%d ",x);}}void initSqStack(SqStack &st){st.top=-1;}int _tmain(int argc, _TCHAR* argv[]){SqStack L;initSqStack(L);for(int i=1;i<=10;i++)push(L,i);show(L);}

以上代码实现了顺序栈的各种操作