Pop

public Node Pop()
{
if (this.top == null)
{
throw new InvalidOperationException("스택이 비어있다.");
}
else
{
Node temp = this.top;
Console.WriteLine("{0}", this.top.Data);
this.top = this.top.Next;
temp.Next = null;
return temp;
}
}
Peek

public Node Peek()
{
if (this.top == null)
{
throw new InvalidOperationException("스택이 비어있다.");
}
else
{
Console.WriteLine("{0}", this.top.Data);
return this.top;
}
}
Node를 반환받으려면 Node클래스의 접근제한자를 public으로 바꿀필요가있다.
'자료구조' 카테고리의 다른 글
Queue Enqueue (0) | 2021.12.28 |
---|---|
스택 복습 (+ Push 순서도) (0) | 2021.12.28 |
스택의 개수를 반환하는 메서드 +재귀적 (0) | 2021.12.28 |
재귀적으로 스택의 모든 데이터를 출력 (0) | 2021.12.28 |
스택 (stack) Push (0) | 2021.12.28 |