// 栈.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);
}

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

相关文章:

  • 2021-07-11
  • 2021-09-29
  • 2022-12-23
  • 2021-11-18
  • 2021-11-16
  • 2021-08-17
  • 2021-06-11
猜你喜欢
  • 2021-11-28
  • 2021-09-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-29
相关资源
相似解决方案