Is the operator legal?

Source: Internet
Author: User
//  Header file  # Include <Stdio. h> # Include <Malloc. h> # Define Maxsize 100 Typedef  Char  Elemtype; typedef  Struct  {Elemtype data [maxsize];  Int Top; /*  Stack pointer  */ } Sqstack;  /*  Sequence stack Type Definition  */  Void Initstack (sqstack *& S) {s = (Sqstack *) malloc ( Sizeof  (Sqstack); s -> Top =- 1  ;}  Void Clearstack (sqstack *& S) {free (s );}  Int Stacklength (sqstack *S ){  Return (S-> top + 1  );}  Int Stackempty (sqstack * S ){  Return (S-> Top =- 1  );}  Int Push (sqstack *& S, elemtype e ){  If (S-> Top = maxsize- 1 ) /* Stack Overflow  */                Return   0  ; S -> Top ++ ; S -> Data [S-> top] = E;  Return   1  ;}  Int Pop (sqstack * & S, elemtype & E ){  If (S-> Top =- 1 )/*  Stack is empty, that is, off-Stack Overflow  */                Return   0  ; E = S-> data [S-> Top]; S -> Top -- ;  Return   1  ;}  Int Gettop (sqstack * s, elemtype & E ){  If (S-> Top =- 1 ) /*  Stack is empty, that is, off-Stack Overflow  */                Return   0  ; E = S-> data [S-> Top];  Return   1  ;}  Void Dispstack (sqstack * S ){  Int  I;  For (I = s-> top; I> =0 ; I -- ) Printf (  "  % C  " , S-> Data [I]); printf (  "  \ N  "  );}  //  Implementation Functions  # Include <Iostream> # Include  "  Heshan1.h "  Using   Namespace  STD;  Int Judge ( Char  A []) {  Int  I; elemtype X; sqstack * S; initstack (s );  For (I = 0 ; A [I]! = '  \ 0  ' ; I ++){  If (A [I] = '  I  '  ) Push (s, A [I]);  Else   If (A [I] = '  O  '  ){  If (S-> Top =- 1 ) // When an "O" operation is performed, the system first checks whether the stack is empty. Otherwise, the operation continues.  {  Return   0  ;}  Else  Pop (S, x );}}  Return (S-> Top =- 1  );}  Void  Main (){  Char A [ 20 ]; Int  I;  For (I = 0 ; I < 20 ; I ++ ) {A [I] = '  \ 0  '  ;} Cout < "  Enter operation sequence (I, O sequence)  " < Endl; CIN >A;  Int M = Judge ();  If (M = 0  ) Cout < "  The operation sequence you entered is invalid.  " < Endl;  Else  Cout < "  The operation sequence you entered is legal  " <Endl ;} 

 

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.