To create a data list dynamically , and display it ----
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
typedef struct list{
int data;
struct list *next;
}node;
node *start=NULL;
void create(int);
void display();
void main()
{int val;
while ()
{printf("\n Enter a number (0 to quit) ; ");
scanf("%d",&x);
if(x==0);
{break;
}
else
{create(val);
}
}
display();
getch();
return;
}
void create(int val)
{node *tmp;
tmp=(node *)malloc(sizeof(node));
tmp->data=val;
tmp->next=NULL;
if(start==NULL)
{start=tmp;
}
else
{q=start;
while (q->next!=NULL)
{q=q->next;
}
q->next=tmp;
}
return;
}
void display()
{node *q;
q=start;
while (q!=null)
{printf("%d,",q->data);
q=q->next;
}
return;
}
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
typedef struct list{
int data;
struct list *next;
}node;
node *start=NULL;
void create(int);
void display();
void main()
{int val;
while ()
{printf("\n Enter a number (0 to quit) ; ");
scanf("%d",&x);
if(x==0);
{break;
}
else
{create(val);
}
}
display();
getch();
return;
}
void create(int val)
{node *tmp;
tmp=(node *)malloc(sizeof(node));
tmp->data=val;
tmp->next=NULL;
if(start==NULL)
{start=tmp;
}
else
{q=start;
while (q->next!=NULL)
{q=q->next;
}
q->next=tmp;
}
return;
}
void display()
{node *q;
q=start;
while (q!=null)
{printf("%d,",q->data);
q=q->next;
}
return;
}
0 Comments