-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathHacktoberfest'22_PR3
94 lines (73 loc) · 1.52 KB
/
Hacktoberfest'22_PR3
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <stdio.h>
#include<stdlib.h>
struct node
{
int num;
struct node* nextptr;
}*stnode;
void createnode(int );
void display();
int main()
{
int n;
printf("enter no of nodes\n");
scanf("%d",&n);
createnode(n);
display();
return 0;
}
void createnode(int x)
{
if(x==0)
return;
struct node*fn,*temp;
int num,i;
stnode=(struct node*)malloc(sizeof(struct node));
if(stnode==NULL)
{
printf("memory cannot be allocated\n");
}
else
{
printf("enter data for node\n");
scanf("%d",&num);
stnode->num=num;
stnode->nextptr=NULL;
temp=stnode;
for(int i=2;i<=x;i++)
{
fn=(struct node*)malloc(sizeof(struct node));
if(fn==NULL)
{
printf("memory cannot be allocated\n");
break;
}
else
{
printf("enter data for node\n");
scanf("%d",&num);
fn->num=num;
fn->nextptr=NULL;
temp->nextptr=fn;
temp=temp->nextptr;
}
}
}
}
void display()
{
struct node *tmp;
if(stnode==NULL)
{
printf("list is empty");
}
else
{
printf("Data entered in the list\n");
tmp=stnode;
while(tmp!=NULL){
printf("Data -> %d\n",tmp->num);
tmp=tmp->nextptr;
}
}
}