Exemple #1
0
        public void push(int data)
        {
            Console.Write("inserted value " + data + "\n");
            StackClassNode node = new StackClassNode(data);

            node.next = top;
            top       = node;
            count++;
        }
Exemple #2
0
        public void printStack()
        {
            StackClassNode runner = top;

            while (runner != null)
            {
                Console.Write("| " + runner.data + " |\n");
                runner = runner.next;
            }
            Console.Write("\n");
        }
Exemple #3
0
        public int pop()
        {
            StackClassNode runner = top;

            int val;

            count--;
            val = runner.data;
            top = runner.next;
            Console.Write("popped value " + val + "\n");
            return(val);
        }
Exemple #4
0
        public bool contain(int data)
        {
            StackClassNode runner = top;

            while (runner != null)
            {
                if (data == runner.data)
                {
                    return(true);
                }
                runner = runner.next;
            }
            return(false);
        }
Exemple #5
0
        public StackClassNode reveserAll()
        {
            StackClassNode runner = top, prev = null;

            if (runner == null)
            {
                return(runner);
            }

            while (runner != null)
            {
                StackClassNode next = runner.next;

                runner.next = prev;
                prev        = runner;

                runner = next;
            }

            top = prev;

            return(top);
        }
Exemple #6
0
 public StackClassNode(int value)
 {
     data = value;
     next = null;
 }
Exemple #7
0
 public Stack()
 {
     top        = null;
     this.count = 0;
 }