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;
}
}
순서도랑 코드 제대로 수정
'자료구조' 카테고리의 다른 글
스택의 개수를 반환하는 메서드 +재귀적 (0) | 2021.12.28 |
---|---|
재귀적으로 스택의 모든 데이터를 출력 (0) | 2021.12.28 |
재귀함수 - Linked List에서 head부터 시작해서 마지막노드 반환 (0) | 2021.12.28 |
재귀함수 - 팩토리얼 (0) | 2021.12.28 |
재귀함수 (0) | 2021.12.28 |