-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay 3 assignment.txt
70 lines (61 loc) · 1001 Bytes
/
Day 3 assignment.txt
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
Question 1]
void insert_any(int item)
{
int posi;
struct node *ptr;
struct node *temp = (struct node *) malloc(sizeof(struct node));
temp->data=item;
int count=0;
printf("Enter the position");
scanf("%d",&posi);
if(posi==1)
loc=NULL;
else
{
ptr=first;
while(count<posi && ptr->link!=NULL)
{
ptr=ptr->link;
count++;
}
loc=ptr;
}
if(loc==NULL)
{
temp->link=first;
first=temp;
}
else
{
temp->link=loc->link;
loc->link=temp;
}
}
Question 2]
void delete_beg()
{
struct node *temp;
if(first==NULL)
{
printf("list is empty\n");
}
temp=first;
first=first->link;
printf("deleted item=%d",temp->data);
free(temp);
}
Question 3]
void delete_end()
{
struct node *loc,*locp;
locp=NULL;
loc=first;
while(loc->link!=NULL)
{
locp=loc;
loc=loc->link;
}
locp->link=NULL;
printf("%d",loc->data);
free(loc);
}