栈( stack )是限定仅在表尾进行插入和删除操作的线性表。
#include
#include
//栈的顺序存储结构,用一维数组实现
#define OK 1
#define ERROR -1
#define TRUE 1
#define FALSE 0
#define MAXSIZE 10
typedef int Status;
typedef int ElemType;
typedef struct {
ElemType data[MAXSIZE];
int top;//栈顶指针
}Stack;
//1. 初始化
Status InitStack(Stack *S){
int i;
for(i=0;i
S->data[i]=NULL;
S->top=-1;
return OK;
}
//2. 创建一个长度为n的堆栈
Status CreateStack(Stack *S,int n){
if(n>MAXSIZE || n<1){
printf("输入长度有误!\n");
return ERROR;
}
srand(time(0));
int i;
for(i=0;i
S->data[i]=rand()%100+1;
}
S->top=n-1;
return OK;