Queue 선입선출
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
namespace Study09
{
class App
{
//생성자
public App()
{
Console.WriteLine("App");
Queue queue = new Queue();
queue.Enqueue(1);
queue.Enqueue("홍길동");
queue.Enqueue(true);
queue.Enqueue(null);
queue.Enqueue(new Hero());
queue.Enqueue(new Queue());
queue.Enqueue(new ArrayList());
object obj0 = queue.Dequeue(); //1
object obj1 = queue.Peek(); //"홍길동"
object obj2 = queue.Dequeue(); //"홍길동"
Console.WriteLine(queue.Count); //5
foreach(object element in queue)
{
Console.WriteLine(element);
}
while (queue.Count > 0)
{
object element = queue.Dequeue();
Console.WriteLine("element: {0}, count: {1}", element, queue.Count);
}
}
}
}
Stack 후입선출
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
namespace Study09
{
class App
{
//생성자
public App()
{
Console.WriteLine("App");
Stack stack = new Stack();
stack.Push(1);
stack.Push(true);
stack.Push("홍길동");
stack.Push(new Hero());
stack.Push(null);
object obj0 = stack.Pop();
object obj1 = stack.Peek();
Console.WriteLine(stack.Count);
foreach(object element in stack)
{
Console.WriteLine(element);
}
while (stack.Count > 0)
{
object element = stack.Pop();
Console.WriteLine("element: {0}, count: {1}", element, stack.Count);
}
}
}
}
'C# > 수업내용' 카테고리의 다른 글
[ C# 8일차 ] Struct 구조체 (0) | 2023.01.10 |
---|---|
[ C# 8일차 ] Collections_Hashtable (0) | 2023.01.10 |
[ C# 8일차 ] Collections_ArrayList (0) | 2023.01.10 |
[ C# 8일차 ] 프로퍼티 (0) | 2023.01.10 |
[C# 7일차] 배열을 이용한 맵 이동 (0) | 2023.01.09 |