Exemplo n.º 1
0
        // return true or false - exist element value in stack.
        public bool Exist(ElementType value)
        {
            if (head == null)
            {
                return(false);
            }
            ListElement temp = head;

            for (temp = head; temp.Next() != null && temp.Value() != value; temp = temp.Next())
            {
                ;
            }
            return(temp.Value() == value);
        }
Exemplo n.º 2
0
        //return position element with vale value.
        public Position PositionElement(ElementType value)
        {
            ListElement temp = head;
            int         i    = 0;

            for (temp = head; temp != null && temp.Value() != value; temp = temp.Next(), i++)
            {
                ;
            }
            if (temp.Value() == value)
            {
                return(i);
            }
            return(-1);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Print stack.
        /// </summary>
        public void Print()
        {
            if (head == null)
            {
                Console.WriteLine("Stack is empty");
                return;
            }
            ListElement pos = head;

            for (pos = head; pos.Next() != null; pos = pos.Next())
            {
                Console.Write("{0} -> ", pos.Value());
            }
            Console.Write("{0}", pos.Value());
            Console.WriteLine();
        }
Exemplo n.º 4
0
        // print stack.
        public void Print()
        {
            Console.WriteLine();
            if (head == null)
            {
                Console.WriteLine("List is Empty");
                return;
            }
            ListElement temp = head;

            for (temp = head; temp.Next() != null; temp = temp.Next())
            {
                Console.Write("{0}, ", temp.Value());
            }
            Console.WriteLine("{0}", temp.Value());
        }