아래 오류 메시지가 나타납니다. 해결할 수 없습니다. 봤 거든. 마침내 그것을 여기에 넣으려고 생각했다.연결된 목록으로 스택 구현
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
int stop;
struct stack
{
int data;
struct stack *next;
};
typedef struct stack *node, *top;
//typedef struct stack *top;
void push()
{
int i;
struct stack *x;
x = malloc(sizeof(struct stack));
printf("\n Enter the element your want to insert");
scanf("%d", &i);
x->data = i;
x->next = top;
top = x;
}
void pop()
{
int i;
if(top == NULL)
{
printf("\nStack is empty\n");
}
else{
i = top->data;
free(top);
top = top->next;
}
}
void display()
{
if(node != NULL)
{
printf("%d ", node->data);
node = node->next;
}
}
int main()
{
int ch;
while(1)
{
printf("\nEnter your option \n1. Insert(Push) \n2. Delete(Pop) \n3. Display : \n");
scanf("%d", &ch);
switch(ch)
{
case 1:
push();
break;
case 2:
pop();
break;
case 3:
display();
break;
default:
printf("Invalid Entery, Try Again");
}
}
return 0;
}
고맙습니다. 많이 ... –
와우, 혼란 스럽습니다. 마지막 줄에서 스택은 struct stack 또는 typedef struct stack 스택을 참조합니까? 별칭의 다른 이름이 더 명확 할 수 있습니다. – Deverill
@Deverill 같은 의미이지만, 마지막 줄의'struct stack'은 태그가 아니라'typedef'-ed 별칭에 의해 참조됩니다. 태그와 동일한 별칭을 사용하는 것이 상대적으로 일반적입니다. – dasblinkenlight