55. Stack class in C#

 using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Collections;

namespace stack_class

{

    class Program

    {

        static void Main(string[] args)

        {

            Stack s1 = new Stack();


            s1.Push(5);

            s1.Push(15);

            s1.Push(25);

            s1.Push(35);

            s1.Push(45);


            foreach (int val in s1)

            {

                Console.WriteLine(val);

            }

            

            s1.Pop();

            s1.Pop();


            Console.WriteLine("==== After POP operation ====");


            foreach (int val in s1)

            {

                Console.WriteLine(val);

            }


            Console.WriteLine("Peek Operation : " + s1.Peek());


            Console.WriteLine("Contains Operation : " + s1.Contains(25));


            Console.WriteLine("Total Element : " + s1.Count);


            Console.WriteLine("==== After Clone of Stack ====");


            Stack s2 = (Stack)s1.Clone();

            foreach (int val in s1)

            {

                Console.WriteLine(val);

            }

            Console.WriteLine("==== After Object into Array ====");


            object[] arr1;

            arr1 = s1.ToArray();


            foreach (object val in arr1)

            {

                Console.WriteLine(val);

            }


            Console.WriteLine("==== After Clear Method ====");

            s1.Clear();

            Console.WriteLine("Total Element : " + s1.Count);


            Console.Read();

        }

    }

}

OUTPUT:
45
35
25
15
5
==== After POP operation ====
25
15
5
Peek Operation : 25
Contains Operation : True
Total Element : 3
==== After Clone of Stack ====
25
15
5
==== After Object into Array ====
25
15
5
==== After Clear Method ====
Total Element : 0

Comments

Popular posts from this blog

Quetion 6 : Consider the "in-order-issue/in-order-completion" execution sequence shown in f In Figure Decode OWE Execute 12 12 12 14 16 13 16 13 15 15 16 Write 024/06/02 11 3 4 11 12 13 13 N 15 16 a. Identify the most likely reason why I could not enter the execute fourth cycle. stage until the [2] b. Will "in-order issue/out-of-order completion" or "out-of-order issue/out-of-order completion" fix this? If so, which? Explain

20.factorial using for loop

JFrame find odd/even