using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Queue
{
class Node
{
public int data;
public Node next;
public Node(int x)
{
data = x;
next = null;
}
}
class Queue
{
Node _front;
Node _rear;
public Queue()
{
_front = null;
_rear = null;
}
public void add(int number)
{
if(_rear == null)
{
_rear = new Node(number);
_front = _rear;
}
else
{
Node p = new Node(number);
_rear.next = p;
_rear = p;
}
}
private void emptyError()
{
Console.WriteLine("Empty");
Environment.Exit(-1);
}
public int remove()
{
if (_front == null) emptyError();
int x = _front.data;
_front = _front.next;
return x;
}
public void print()
{
Node p;
p = _front;
while(p != null)
{
Console.Write(p.data + "");
p = p.next;
Console.WriteLine();
}
}
}
class Program
{
static void Main(string[] args)
{
Queue q = new Queue();
q.add(10);
q.add(20);
q.add(30);
q.remove();
q.add(40); q.add(50);
q.add(60); q.add(70);
q.remove();
q.print();
}
}
}
'Programming > C#' 카테고리의 다른 글
Growable Array 큐 (0) | 2018.11.05 |
---|---|
단순 overflow 큐 (0) | 2018.11.05 |
[C#] 파일 입출력 정리 (0) | 2018.06.06 |