/*
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct DNode
{
char data[10];
struct DNode* llink;
struct DNode* rlink;
}Dnode;
typedef struct
{
Dnode* head;
}dnode_h;
dnode_h* createDLList_h(void);
void addLastNode(dnode_h*, char*);
void deleteLastNode(dnode_h*);
void addmiddleNode(dnode_h*, Dnode* pre, char*);
void printList(dnode_h*);
dnode_h* createDLList_h(void)
{
dnode_h* L;
L=(dnode_h*)malloc(sizeof(dnode_h));
L->head=NULL;
return L;
}
void addLastNode(dnode_h* L, char *x)
{
Dnode* newNode;
Dnode* p;
newNode=(Dnode*)malloc(sizeof(Dnode));
strcpy(newNode->data, x);
if(L->head==NULL){
L->head=newNode;
newNode->rlink=NULL;
return;
}
p=L->head;
while(p->rlink!=NULL) p=p->rlink;
//p는 마지막 노드
newNode->rlink=NULL;
p->rlink=newNode;
newNode->llink=p;
}
void addmiddleNode(dnode_h* L, Dnode* pre, char* x)
{
Dnode* newNode;
newNode=(Dnode*)malloc(sizeof(Dnode));
strcpy(newNode->data, x);
if(L->head==NULL){
L->head=newNode;
newNode->rlink=NULL;
return;
}
newNode->rlink=pre->rlink;
pre->rlink=newNode;
newNode->llink=pre;
newNode->rlink->llink=newNode;
}
void deleteLastNode(dnode_h* L)
{
Dnode* pre;
Dnode* cur;
if(L->head==NULL) return;
if(L->head->rlink==NULL){
free(L->head);
L->head=NULL;
return;
}
else {
pre=L->head;
cur=L->head->rlink;
while(cur->rlink!=NULL){
pre=cur;
cur=cur->rlink;
}
free(cur);
pre->rlink=NULL;
}
}
void printList(dnode_h* L)
{
Dnode* p;
printf("L=(");
p=L->head;
while(p!=NULL){
printf("%s", p->data);
p=p->rlink;
if(p!=NULL) printf(", ");
}
printf(") \n");
}
int main()
{
dnode_h* L;
L=createDLList_h();
printf("(1) 공백 리스트 생성하기 \n");
printList(L); getchar();
printf("(2) 리스트에 3개의 노드 추가하기 \n");
addLastNode(L, "월");
addLastNode(L, "수");
addLastNode(L, "금");
printList(L); getchar();
printf("(3) 리스트 마지막 노드에 1개의 노드 추가하기 \n");
addLastNode(L, "일");
printList(L); getchar();
printf("(4) 리스트 중간 노드에 1개의 노드 추가하기 \n");
addmiddleNode(L, L->head->rlink ,"토");
printList(L); getchar();
printf("(5) 마지막 노드 삭제하기 \n");
deleteLastNode(L);
printList(L); getchar();
getchar();
return 0;
}
*/
/*
#include <stdio.h>
#include <stdlib.h>
#define SIZE 10
char stack[SIZE];
int top; //데이터가 마지막으로 들어간 위치
void initstack()
{
top=-1;
}
void push(char item)
{
if(top+1 == SIZE) return;
stack[++top]=item;
}
char pop()
{
if(top==-1) {
printf("stack is empty!!!\n");
return 0;
}
//null이라는 문자는 입력받지 않는다는 가정 하에
return stack[top--];
}
void printstack()
{
int i;
printf("STACK [");
for(i=0;i<=top;i++){
printf("%c ", stack[i]);
}
printf("]\n\n");
}
int main()
{
int item;
initstack();
printstack();
push('a');
printstack();
push('c');
printstack();
push('e');
printstack();
printf("pop data is %c\n",pop());
printstack();
printf("pop data is %c\n",pop());
printstack();
printf("pop data is %c\n",pop());
printstack();
printf("pop data is %c\n",pop());
printstack();
getchar();
}
*/