forked from gouravthakur39/beginners-C-program-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Linked List Creation
47 lines (47 loc) · 758 Bytes
/
Linked List Creation
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
#include<stdio.h>
#include<stdlib.h>
int n;
struct node
{
int data;
struct node *info;
}*start;
void create(int n)
{
int i;
struct node *temp,*p,*newnode;
p=(struct node *)malloc(sizeof(struct node));
start=p;
printf("enter the data\n");
scanf("%d",&p->data);
p->info=NULL;
temp=start;
for(i=2;i<=n;i++)
{
newnode=(struct node *)malloc(sizeof(struct node));
printf("enter the data\n");
scanf("%d",&newnode->data);
newnode->info=NULL;
temp->info=newnode;
temp=temp->info;
}
}
void display()
{
struct node *temp;
temp=start;
while(temp!=NULL)
{
printf("%d",temp->data);
temp=temp->info;
}
}
int main()
{
printf("enter the no of node");
scanf("%d",&n);
create(n);
printf("\n");
display();
return 0;
}