Linked List
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
struct NODE
{
int info;
struct NODE* next;
};
NODE* createnode(int d)
{
NODE* temp;
temp=(NODE*)malloc(sizeof(NODE));
temp->info=d;
temp->next=NULL;
return(temp);
}
void insertnode(NODE **start)
{
int d;
NODE* temp;
printf("enter info");
scanf("%d",&d);
temp=createnode(d);
temp->next=*start;
*start=temp;
}
void showlist(NODE **start)
{
NODE *temp;
if(*start==NULL)
printf("empty\n");
else
{
temp=*start;
while(temp->next!=NULL)
printf("%d ",temp->info);
printf("%d ",temp->info);
}
}
int main()
{
int choice;
char a;
NODE* start;
start=NULL;
do
{
printf("1.insert \n2.showlist\n");
scanf("%d",&choice);
if(choice==1)
insertnode(&start);
else
showlist(&start);
printf("do u wanna go again(y/n)");
scanf("\n%c",&a);
}while(a=='y');
getch();
}
|
the showlist function runs an infinte loop...could anyone please find out the bug?
Try adding temp= temp-> next after printfs
oops..i missed it..thnx for pointing out..
Topic archived. No new replies allowed.