C#/C# Concept

[C#] Stack

군우 2018. 5. 24. 10:40



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System;
using System.Collections;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace ConsoleApplication16
{
    class StackTest
    {
        static void Main(string[] args)
        {
            Stack stack = new Stack();
            stack.Push("Hi");
            stack.Push("Hello");
            stack.Push("World");
            stack.Push("7777");
            Print("1. stack의 목록:",stack);
 
            object obj = stack.Pop();
            Console.WriteLine("2.pop:{0}", obj);
            obj = stack.Pop();
            Console.WriteLine("3.pop:{0}", obj);
            Print("4. pop을 두번한 후의 목록:", stack);
 
            obj = stack.Peek();
            Console.WriteLine("5. Peek: {0}",obj);
 
        }
 
        public static void Print(string info, IEnumerable myCollection)
        {
            Console.Write(info + "\n\t");
            IEnumerator myEnumerator = myCollection.GetEnumerator();
            while (myEnumerator.MoveNext())
                Console.Write("{0}, ", myEnumerator.Current);
            Console.WriteLine();
        }
 
    }
}
 
cs






1. stack의 목록:

        7777, World, Hello, Hi,

2.pop:7777

3.pop:World

4. pop을 두번한 후의 목록:

        Hello, Hi,

5. Peek: Hello

계속하려면 아무 키나 누르십시오 . . .