Stack

作者: 綿綿_ | 来源:发表于2019-03-29 15:25 被阅读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]);
        }

相关文章

网友评论

      本文标题:Stack

      本文链接:https://www.haomeiwen.com/subject/rhdlbqtx.html