-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirst_node.c
65 lines (65 loc) · 1.02 KB
/
first_node.c
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
#include<stdio.h>
#include<conio.h>
void create_link_list(int);
void Display();
struct node
{
int info;
struct node *link;
}*first;
void main()
{
int ch,item;
do
{
printf("\n(1)Insert Element into list\n(2)View Inserted Element\n(3)Exit\n\nEnter choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\nEnter items:");
scanf("%d",&item);
create_link_list(item);
break;
case 2:
Display();
break;
}
} while(ch<=2);
}
void create_link_list(int item)
{
struct node *newnode, *temp;
newnode=(struct node*)malloc(sizeof(struct node));
if(newnode==NULL)
{
printf("\nMemory not allocated");
getch();
return;
}
newnode->info=item;
newnode->link=NULL;
if(first==NULL)
{
first=newnode;
return;
}
temp=first;
while(temp->link!=NULL)
{
temp=temp->link;
}
temp->link=newnode;
return;
}
void Display()
{
struct node *temp;
temp=first;
while(temp!=NULL)
{
printf("\t %d",temp->info);
temp=temp->link;
}
getch();
}