티스토리 뷰
// LinkedStack.cpp : 콘솔 응용 프로그램에 대한 진입점을 정의합니다.
//
#include "stdafx.h"
// 단일 포인터 이용
struct Node
{
int data;
Node *next;
};
Node *head = 0;
void Push(int r)
{
Node *p = new Node;
p->data = r;
p->next = head;
head = p;
}
int Pop()
{
Node *p = head;
head = p->next;
int r = p->data;
delete p;
return r;
}
int _tmain(int argc, _TCHAR* argv[])
{
for( int i = 1; i <= 10; i++ )
Push(i);
for( int i = 0; i < 10; i++ )
printf( "%d ", Pop() );
printf( "\n" );
return 0;
}
실행결과
#include "stdafx.h"
// 이중 포인터 이용
struct Node
{
int data;
Node *next;
};
void Push(Node **head, int r)
{
Node *p = new Node;
p->data = r;
p->next = *head;
*head = p;
}
int Pop(Node **head)
{
Node *p = *head;
*head = p->next;
int r = p->data;
delete p;
return r;
}
int _tmain(int argc, _TCHAR* argv[])
{
Node *head = 0;
for( int i = 1; i <= 10; i++ )
Push(&head, i);
for( int i = 0; i < 10; i++ )
printf( "%d ", Pop(&head) );
printf( "\n" );
return 0;
}
실행결과
- Total
- Today
- Yesterday
- 가을
- 겨울
- NDS
- NDSi
- 웃기는 사진
- DLC
- ndsl
- Project Diet
- 3분 영어 위클리
- 아이폰
- 젤다의 전설
- C/C++
- 군대이야기
- CNN Student News
- 동물의숲
- 티스토리달력2010
- 2011사진공모전
- 슈퍼마리오 RPG
- oracle
- 오라클
- jsp
- 야생의 숨결
- Wii GAME
- 게시판
- NDS GAME LIST
- 스포어
- Spore
- 동유럽
- 티스토리달력2011
- Free Coupon
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |