在这个方案中,我有段故障错误,任何一个点在哪里,我是在这个程序的内存分配错误。
//stack program
#include<stdio.h>
#include<conio.h>
struct node
{
int data;
struct node *next; //this variable is refer the same structure
}*top=NULL;
int main()
{
// clrscr();
insert(34); //insert node
insert(20);
display();
// getch();
return 0;
}
// insert new stack value
insert(int val)
{
struct node *temp = (struct node *)malloc(sizeof(struct node));
temp = top;
temp->data = val;
temp->next = top;
top = temp;
}
//display the stack
display()
{
struct node *temp = top;
while(temp)
{
printf("%d",temp->data);
temp = temp->next;
}
}