자료구조
Pop + peek
hyunjin-dev-log
2021. 12. 28. 14:41
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으로 바꿀필요가있다.