public int Dequeue()
{
if (head == null)
{
throw new InvalidOperationException("큐가 비어있다.");
}
else
{
int data = this.head.data;
if (this.head.next == null)
{
this.head = null;
this.tail = null;
}
else
{
Node temp = this.head; // 이작업 해주면 좋다.
this.head = this.head.next;
temp.next = null; // 아이템 꺼내고 인벤토리에서 제거해주는것과 같은맥락
}
return data;
}
}
'자료구조' 카테고리의 다른 글
Queue Count (0) | 2021.12.28 |
---|---|
Queue Peek (0) | 2021.12.28 |
Queue Enqueue (0) | 2021.12.28 |
스택 복습 (+ Push 순서도) (0) | 2021.12.28 |
Pop + peek (0) | 2021.12.28 |