-
Notifications
You must be signed in to change notification settings - Fork 0
/
LinklistBeginsert.c
80 lines (55 loc) · 1.82 KB
/
LinklistBeginsert.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct node
{
int data;
struct node *next;
};
void traverse(struct node *head)
{
while(head!=NULL)
{
printf("Element :%d\n",head->data);
head=head->next;
}
}
struct node * beginsert(struct node *head)
{
int data;
struct node *ptr=(struct node *)malloc(sizeof(struct node));
printf("enter insert element :");
scanf("%d",&data);
ptr->data=data;
ptr->next=head;
}
int main()
{
struct node *head;
struct node *second;
struct node *third;
struct node *four;
struct node *five;
head=(struct node *)malloc(sizeof(struct node));
second=(struct node *)malloc(sizeof(struct node));
third=(struct node *)malloc(sizeof(struct node));
four=(struct node *)malloc(sizeof(struct node));
five=(struct node *)malloc(sizeof(struct node));
head->data=10;
head->next=second;
second->data=20;
second->next=third;
third->data=30;
third->next=four;
four->data=40;
four->next=five;
five->data=50;
five->next=NULL;
printf("Before insertion element is");
traverse(head);
head=beginsert(head);
printf("nAfter insertion element in link ist:\n");
traverse(head);
getch();
return 0;
}