数据结构----栈

 

 

class StackX {

    privateint maxSize; // size of stack array

    privatedouble[]  stackArray;

    privateint top; // top of stack

    //-------------------------------------------------------------

 

    public StackX(int s) // constructor

    {

        maxSize = s; // set array size

        stackArray = newdouble[maxSize]; // create array

        top = -1; // no items yet

    }

 

    //-------------------------------------------------------------

 

    publicvoid push(double j) // put item on top of stack

    {

        stackArray[++top] = j; // increment top, insert item

    }

 

    //-------------------------------------------------------------

 

    publicdouble pop() // take item from top of stack

    {

        returnstackArray[top--]; // access item, decrement top

    }

 

    //-------------------------------------------------------------

 

    publicdouble peek() // peek at top of stack

    {

        returnstackArray[top];

    }

 

    //-------------------------------------------------------------

 

    publicboolean isEmpty() // true if stack is empty

    {

        // - 94 -

        return (top == -1);

    }

 

    //-------------------------------------------------------------

    publicboolean isFull() // true if stack is full

    {

        return (top == maxSize - 1);

    }

    //-------------------------------------------------------------

} // end class StackX

 

栈中,

maxSize:描述栈的大小

stackArray描述栈的类型数组

top:描述栈的指针

push(double j):在栈里加数据的方法

pop():在栈里去数据的方法

peek():取出当前栈中指针指向的数据

isEmpty():判断栈中是不是还有数据

isFull():判读栈是不是满了

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值