-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinkedlist3.c
52 lines (44 loc) · 997 Bytes
/
linkedlist3.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
#include<stdio.h>
#include<stdlib.h>
struct Node
{
int data;
struct Node*next;
};
struct Node*head,*temp;
void printlist(struct Node*n)
{
while(n!=NULL){
printf("%d \t",n->data);
n=n->next;
}
}
void main()
{
struct Node*second=NULL;
struct Node*third=NULL;
struct Node*newnode;
head=(struct Node*)malloc(sizeof(struct Node));
second=(struct Node*)malloc(sizeof(struct Node));
third=(struct Node*)malloc(sizeof(struct Node));
newnode=(struct Node*)malloc(sizeof(struct Node));
head->data=98;
head->next=second;
second->data=99;
second->next=third;
third->data=100;
third->next=NULL;
temp=head;
printf("linked list before insertion at beginning:\n");
printlist(head);
printf("\n");
printf("Enter the number to be inserted :\n");
scanf("%d",&newnode->data);
while(temp->next!=NULL){
temp=temp->next;
}
temp->next=newnode;
newnode->next=NULL;
printf("Linklist is as follow after insertion after beginning:\n");
printlist(head);
}