标签:
#include<iostream>
//#include<time.h>
//#include <stdlib.h>
using namespace std;
#define OK 1
#define TRUE 1
#define FALSE 0
#define ERROR 0
#define MAXSIZE 100//数组的最大大小
typedef int status;//返回的状态值
typedef int elemtype;//节点里数据的类型
typedef struct
{
elemtype data[MAXSIZE];//存放栈数据的数组
int top;//指示栈顶元素的下标,假定当为空栈的时候为-1
}stacklist;
//进栈操作
status push_stack(stacklist *L,elemtype e)
{
if(L->top==MAXSIZE-1)
return ERROR;
L->top++;
L->data[L->top]=e;
return OK;
}
//出栈操作
status pull_stack(stacklist *L,elemtype &e)
{
if(L->top==-1)
return ERROR;
e=(L->data[L->top]);
L->top--;
return OK;
}
void max(int &a,int &b)
{
int temp;
if(a>=b)
{
temp=a;
a=b;
b=temp;
}
}
int main()
{
stacklist L;
L.data[0]=1;
L.data[1]=2;
L.data[2]=3;
L.top=2;
push_stack(&L,6);
cout<<L.top<<‘ ‘<<L.data[L.top]<<endl;
elemtype e=2;
pull_stack(&L,e);
cout<<e<<endl;
system("pause");
return 1;
}
标签:
原文地址:http://www.cnblogs.com/yanliang12138/p/4328263.html