~cpp
#include <iostream.h>
struct node{
int data;
node * node_pointer;
};
node * INSERT(node * head_pointer, int num);
node * DELETE(node * head_pointer);
int main()
{
//택 킨 포
node * head_pointer = new node;
// 키 포 화
head_pointer = NULL;
int num, choice;
//택
cout << "택 !!\n";
cout << "1.push 2.pop 3.exit\nchoice : ";
cin >> choice;
while(choice != 3)
{
switch(choice)
{
case 1://push
cout << "push num : ";
cin >> num;
head_pointer = INSERT(head_pointer, num);
break;
case 2://pop
head_pointer = DELETE(head_pointer);
break;
}
cout << "\n택 !!\n";
cout << "1.push 2.pop 3.exit\nchoice : ";
cin >> choice;
}
return 0;
}
//택
node * INSERT(node * head_pointer, int num)
{
node * temp = new node;
// 택
if(head_pointer == NULL)
{
head_pointer = temp;
head_pointer->data = num;
head_pointer->node_pointer = NULL;
}
else
{
temp->node_pointer = head_pointer;
head_pointer = temp;
head_pointer->data = num;
}
return head_pointer;
}
//택
node * DELETE(node * head_pointer)
{
node * temp = new node;
//택
if(head_pointer == NULL)
cout << "no data in stack" << "\n";
else
{
cout << "delete num : " << head_pointer->data << "\n";
temp = head_pointer;
head_pointer = head_pointer->node_pointer;
delete temp;
}
return head_pointer;
}