[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/githqj/JavaArithmetic/master/src/stack/StackTest.java [Back]  [Original]

package stack;

/**
 * Created by ozc on 2018/3/28.
 *
 * @author ozc
 * @version 1.0
 */

public class StackTest {


    public static void main(String[] args) {

        //()
        Stack stack = new Stack(new Node(), new Node());

        //
        stack.stackBottom = stack.stackTop;

        //null
        stack.stackTop.next = null;

        //
        pushStack(stack, 3);
        pushStack(stack, 4);
        pushStack(stack, 5);

        traverse(stack);
        isEmpty(stack);

        // 
/*        popStack(stack);
        popStack(stack);
        popStack(stack);
        popStack(stack);
        popStack(stack);*/

        clearStack(stack);


        isEmpty(stack);

    }


    /**
     * 
     *
     * @param stack 
     * @param value 
     */
    public static void pushStack(Stack stack, int value) {

        // 
        Node newNode = new Node(value);


        // 
        newNode.next = stack.stackTop;

        // 
        stack.stackTop = newNode;

    }


    /**
     * ()
     *
     * @param stack
     */
    public static void traverse(Stack stack) {
        Node stackTop = stack.stackTop;

        while (stackTop != stack.stackBottom) {

            System.out.println("Java3y" + stackTop.data);

            stackTop = stackTop.next;
        }
    }

    /**
     * 
     *
     * @param stack
     */
    public static boolean isEmpty(Stack stack) {
        if (stack.stackTop == stack.stackBottom) {

            System.out.println("Java3y---->");
            return true;
        } else {

            System.out.println("Java3y---->");

            return false;
        }

    }

    /**
     * ()
     * @param stack
     */
    public static void popStack(Stack stack) {

        // 
        if (!isEmpty(stack)) {

            //
            Node top = stack.stackTop;

            // 
            stack.stackTop = top.next;

            System.out.println("Java3y---->" + top.data);

        }
    }

    /**
     * 
     * @param stack
     */
    public static void clearStack(Stack stack) {

        stack.stackTop = null;
        stack.stackBottom = stack.stackTop;
    }


}

Web Proxy Viewer  |  New URL  |  Original Page