-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinked_list_implementation.c
More file actions
49 lines (45 loc) · 1.04 KB
/
Copy pathLinked_list_implementation.c
File metadata and controls
49 lines (45 loc) · 1.04 KB
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
// Linked List implementation in C
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node *link;
};
struct node *head = NULL;
int main()
{
struct node *newnode, *temp = NULL;
int n = 1;
while(n == 1)
{
newnode = (struct node *)malloc(sizeof(struct node));
if(newnode==NULL)
{
printf("Memory Not allocate.");
}
else
{
printf("Enter the data\n");
scanf("%d", &newnode->data);
newnode->link = NULL;
if (head == NULL)
head = temp = newnode;
else
{
temp->link = newnode;
temp = temp->link;
}
printf("Do You want to create another node, if yes press 1, else 0\n");
scanf("%d", &n);
}
}
temp = head;
printf("\nAfter creation of Linked List the data of Linked List are\n");
while(temp!=NULL)
{
printf("%d\n", temp->data);
temp = temp->link;
}
return 0;
}