본문 바로가기

자료구조

스택 (stack) Push

1. 비어있는경우

public void Push(int data)
{
    Node node = new Node(data);
    if (this.top == null)
    {
    this.top = node;
    }
}

2. 비어있지 않은경우

public void Push(int data)
{
    Node node = new Node(data);
    if (this.top == null)
    {
      this.top = node;
    }
    else
    {
      Node temp = this.top;
      this.top = node;
      this.top.Next = temp;
    }
}

순서도랑 코드 제대로 수정