我收到以下錯誤消息。 無法解決它。 Google搜索了很多。最後想到把它放在這裏。按鏈接列表執行堆棧
#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;
}
非常感謝... – 2012-04-24 13:52:44
哇,這很混亂。在最後一行中,堆棧是指struct struct還是typedef struct stack stack?也許別名的另一個名字會更清晰。 – Deverill 2012-04-24 13:57:13
@Deverill同樣的事情,但在最後一行'struct stack'被它的'typedef'-alias引用,而不是它的標籤。使用與標籤相同的別名是相對常見的做法。 – dasblinkenlight 2012-04-24 13:59:56