6.3w+
社区成员
//SeqStack.h
#define TRUE 1
#define FALSE 0
#define STACK_SIZE 20
typedef int ElementType;
typedef struct
...{
ElementType data[STACK_SIZE];
int top;
}SeqStack;
void InitStack(SeqStack *s) ...{
s->top = -1;
}
int IsEmpty(SeqStack *s) ...{
if(s->top == -1) return TRUE;
return FALSE;
}
int IsFull(SeqStack *s) ...{
if(s->top == STACK_SIZE-1) return TRUE;
return FALSE;
}
int Push(SeqStack *s, ElementType element) ...{
if(IsFull(s)) return FALSE;
s->top ++;
s->data[s->top] = element;
return TRUE;
}
int Pop(SeqStack *s, ElementType *element) ...{
if(IsEmpty(s)) return FALSE;
*element = s->data[s->top];
s->top --;
return TRUE;
}
int GetTop(SeqStack *s,ElementType *element) ...{
if(IsEmpty(s)) return FALSE;
*element = s->data[s->top];
return TRUE;
}
//SeqStackTest.cpp
#include <stdio.h>
#include "SeqStack.h"
void main() ...{
//initialization
SeqStack s;
InitStack(&s);
//input
for(int i=0; i<20; i++) ...{
Push(&s,i);
}
//output
while(!IsEmpty(&s)) ...{
int rslt;
Pop(&s,&rslt);
printf("%d ",rslt);
}
}