Data structures-sequential stacks

Source: Internet
Author: User

1#include <iostream>2#include <stdlib.h>3 using namespacestd;4 5 #defineMaxSize 306 7typedefstruct8 {9     intData[maxsize];Ten     inttop; One }sqstack; A  - voidInitstack (Sqstack &S) - { thes.top=-1; - } -  - intIsEmpty (sqstack S) + { -     if(s.top==-1) +         return 1; A     Else at         return 0; - } -  - intPush (Sqstack &s,inte) - { -     if(s.top==maxsize-1) in         return 0; -++(s.top); tos.data[s.top]=e; +     return 1; - } the  * intPop (Sqstack &s,int&e) $ {Panax Notoginseng     if(s.top==-1) -         return 0; theE=S.data[s.top]; +--(s.top); A     return 0; the } +  - intGetTop (Sqstack S,int&e) $ { $     if(s.top==-1) -         return 0; -E=S.data[s.top]; the--(s.top); -     return 1;Wuyi } the  - voidPrint (sqstack S) Wu { -     if(s.top==-1) Aboutcout<<"The order stack is empty! "<<Endl; $     Else -     { -          while(s.top!=-1) -         { Acout<<"  "<<S.data[S.top--]<<"  "; +         } the     } - } $  the intMain () the { the     intI=0; the     inte; - Sqstack S; in Initstack (S); the  thecout<<"\ n--------------------------------\ n"; Aboutcout<<"\ n The elements in the sequential stack are: \ n"; the      for(i=0;i<Ten;++i) the Push (s,i); the Print (S); +     if((E=isempty (S)) = =1) -cout<<"\ n The sequential stack is empty! \ n"; the     ElseBayicout<<"\ n Sequential stack is not empty! \ n"; the  thecout<<"\ n--------------------------------\ n"; -cout<<"\ nthe element in the sequence stack after removing the top element of the stack is: \ n"; - Pop (s,e); the Print (S); the  thecout<<"\ n--------------------------------\ n"; the GetTop (s,e); -cout<<"\ nthe top element of this stack is:"<<e<<Endl; thecout<<"\ n The elements in the sequential stack are: \ n"; the Print (S); the     return 0;94}

Data structures-sequential stacks

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.