c언어 연결스택 질문이요
딸기맛사탕
스택에 넣었다가 출력하는 프로그램을 짜야되는데 여기서 연결스택 이용해서 코딩해주시면 감사하겠습니다.ㅜ#include stdio.h
#include malloc.h
#include string.h
struct Node
{
char str[10];
struct Node* prev;
struct Node* next;
}; struct Node* insert_data( struct Node* head, char* str )
{
struct Node *node, *temp1 = head, *temp2 = NULL; node = (struct Node*)malloc(sizeof(struct Node));
node-next = node-prev = NULL;
strcpy( node-str, str ); while( temp1 )
{
if( strcmp( str, temp1-str ) 0 )
{
temp2 = temp1-prev;
if( temp2 )
{
temp2-next = node;
temp1-prev = node;
node-prev = temp2;
node-next = temp1;
return head;
}
else
{
node-next = head;
head-prev = node;
return node;
}
}
temp2 = temp1;
temp1 = temp1-next;
} if( temp2 )
{
temp2-next = node;
node-prev = temp2;
}
else
{
head = node;
}
return head;
} void print_data( struct Node* head )
{
struct Node *node = head;
while( node )
{
printf(%s , node-str);
node = node-next;
}
printf(\n);
} void main()
{
int i;
struct Node *head = NULL;
char* mon[10] = { 박지성, 기성용, 이청용, 김보경, 손흥민, 구자철, 홍정호, 지동원, 류승우, 윤석영 };
printf(20114856 이지성\n); for( i=0; i10; i++ )
{
head = insert_data( head, mon[i] );
}
print_data(head);
}