C#/수업내용
03/17 queue 연습
박준희
2021. 3. 17. 17:55
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study06
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Main");
new App();
}
}
}
App.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study06
{
public class App
{
public App()
{
Console.WriteLine("App");
//Queue<Unit> 변수 선언
Queue<Unit> units;
//Queue 객체 생성하고 변수에 할당
units = new Queue<Unit>();
//Unit객체 생성
Unit unit1 = new Unit("캐리어1");
Unit unit2 = new Unit("스카웃1");
Unit unit3 = new Unit("스카웃2");
Unit unit4 = new Unit("캐리어2");
Unit unit5 = new Unit("커세어1");
//Enqueue
units.Enqueue(unit1);
units.Enqueue(unit2);
units.Enqueue(unit3);
units.Enqueue(unit4);
units.Enqueue(unit5);
//요소 수 출력
Console.WriteLine("요소 수 출력 : " + units.Count);
//요소 출력 (유닛의 이름)
foreach(Unit unit in units)
{
Console.WriteLine(unit.Name);
}
Console.WriteLine("***** Dequeue *****");
//Dequeue
Unit dequeueUnit = units.Dequeue();
Console.WriteLine(dequeueUnit.Name);
//요소 수 출력
Console.WriteLine("요소 수 출력 : " + units.Count);
Console.WriteLine("***** Peek *****");
//보기 (유닛의 이름)
Unit peekUnit = units.Peek();
Console.WriteLine(peekUnit.Name);
//요소 수 출력
Console.WriteLine("요소 수 출력 : " + units.Count);
}
}
}
Unit.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study06
{
public class Unit
{
public string Name { get; private set; }
public Unit(string name)
{
Name = name;
}
}
}