Exemplo n.º 1
0
        public void Push(T NewStack)
        {
            //If is empty
            if (!IsNotEmpty)
            {
                //First time HasPushed
                IsNotEmpty = true;

                //Create temp
                Temp = new mstack <T>();

                //Assign NewStack to temp
                Temp.Data = NewStack;
            }
            else
            {
                //Assign Next
                Next = new mstack <T>();

                //Make Next point to temp
                Next.Next = Temp;

                //Make temp point to next
                Temp = Next;

                //Asign Temp.Data to NewStack
                Temp.Data = NewStack;

                //Make next not point to next
                Next = null;
            }
        }
Exemplo n.º 2
0
        public T Pop()
        {
            //If the stack isnt empty
            if (IsNotEmpty)
            {
                //Create a placeholder for the data
                T PlaceHolder = Temp.Data;

                //Remove it from the stack
                Temp = Temp.Next;

                //if it is empty, IsEmpty = false
                if (Temp == null)
                {
                    IsNotEmpty = false;
                }

                return(PlaceHolder);
            }
            else
            {
                return(Data);
            }
        }
Exemplo n.º 3
0
        public static void Main(string[] args)
        {
            mstack <Mstring> ms2 = new mstack <Mstring>();

            Mstring one = new Mstring("louie");
            Mstring two = new Mstring("marshy");

            ms2.Push(one);
            ms2.Push(two);



            mstack2 stack = new mstack2();

            stack.Push(10);
            stack.Push(20);
            stack.Push(30);

            Console.WriteLine(stack.Pop());
            Console.WriteLine(stack.Pop());
            Console.WriteLine(stack.Pop());


            for (int i = 0; i < 10000; i++)
            {
                stack.Push(i);
            }

            Console.WriteLine("*********************NOW POP IT*********************");
            Console.WriteLine("*********************NOW POP IT*********************");
            Console.WriteLine("*********************NOW POP IT*********************");
            Console.WriteLine("*********************NOW POP IT*********************");
            Console.WriteLine("*********************NOW POP IT*********************");
            Console.WriteLine("*********************NOW POP IT*********************");
            Console.WriteLine("*********************NOW POP IT*********************");
            Console.WriteLine("*********************NOW POP IT*********************");

            int j = 0;

            while (stack.Pop() != 0)
            {
            }

            Console.ReadKey();


            mstack <int> ms = new mstack <int>();

            for (int i = 0; i < 10000; i++)
            {
                ms.Push(i);
            }

            Console.WriteLine("*********************NOW POP IT*********************");
            Console.WriteLine("*********************NOW POP IT*********************");
            Console.WriteLine("*********************NOW POP IT*********************");
            Console.WriteLine("*********************NOW POP IT*********************");
            Console.WriteLine("*********************NOW POP IT*********************");
            Console.WriteLine("*********************NOW POP IT*********************");
            Console.WriteLine("*********************NOW POP IT*********************");
            Console.WriteLine("*********************NOW POP IT*********************");

            j = 0;
            while (ms.Pop() != 0)
            {
            }
        }