Stack

2019-03-29  本文已影响0人  綿綿_

Initialize stack

StackType STInit()

        {
            StackType p;
            if ((p=new StackType())!=null)
            {
                p.top=0;
                return p;
            }
        return null;
        }

Is Empty?

boolean STIsEmpty(StackType s)
        {
            boolean t;
            t=(s.top==0);
            return t;
        }

Is Full?

boolean STIsFull()(StackType s)
        {
            boolean t;
            t=(s.top==MAXLEN);
            return t;
        }

Clear the stack

void STClear(StackType s)
        {
            s.top=0;
        }

Release memory

 void STFree(StackType s)
        {
            if(s!=null)
            {
                s=null;
            }
        }

Push

int PushST(StackType s, DATA3 data)
        {
            if(s.top==MAXLEN)
            {
                System.out.println("memory full");
                return 0;
            }
            top=top+1;
            s.data[s.top++]=data;
            return 1;
        }

Pop

DATA3  PopST(StackTypes s , DATA3 data)
        {
            if(s.top==0)
            {
                System.out.println("empty stack");
                System.exit(0);
            }
            return(s.data[s.top--]);
            
      

Peek

 DATA3 PeekST(StackType s)
        {
            if(s.top==0)
            {
                System.out.print("empty stack");
                System.exit(0);
            }
            return(s.data[s.top]);
        }
上一篇 下一篇

猜你喜欢

热点阅读