C语言堆栈(整理).pptxVIP

  • 0
  • 0
  • 约1.15千字
  • 约 3页
  • 2020-10-22 发布于广东
  • 举报
#includestdio.h #include Stack.h #include StackCommonFunction.h void main() { Stack s; T x; CreateStack(s,10); Push(s,10); Push(s,15); PrintStack(s); x=*InputElement(); Push(s,x); PrintStack(s); Pop(s); Pop(s); if(IsEmpty(s)) printf(Is Empty!\n); else printf(Is not Empty!\n); PrintStack(s); } #includestdio.h #include Stack.h #include StackCommonFunction.h T *InputElement() { static T a; scanf(%d,a); return a; } void PrintElement(T x) { printf(%d ,x); } void PrintStack(Stack s) { if(IsEmpty(s)) printf(The Stack is empty!\n); else for(;s.Top=0;s.Top--) PrintElement(s.Element[s.Top]);;} void CreateStack(Stack *s,int maxsize) { s-Top=-1; s-MaxSize=maxsize; } BOOL IsEmpty(Stack s) { return s.Top0; } BOOL IsFull(Stack s) { return s.Top=s.MaxSize-1; } void Push(Stack *s,T x) { if(IsFull(*s)) printf(Overflow!\n); else { s-Top++; s-Element[s-Top]=x; } } void Pop(Stack *s) { if(IsEmpty(*s)) printf(Underflow!\n); else s-Top--; } void StackTop(Stack s,T *x) { if(IsEmpty(s)) printf(Underflow); else *x=s.Element[s.Top]; } #ifndef STACK_H #define STACK_H #define MAXSIZE 50 #define FALSE 0;3

文档评论(0)

1亿VIP精品文档

相关文档