forked from akash98765/C-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
del.h
49 lines (49 loc) · 949 Bytes
/
del.h
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
#include "work.h"
#ifndef DEL_H
#define DEL_H
void del()
{ int w;
int found=0;
struct employee *a=(struct employee*)malloc(sizeof(struct employee));
struct employee *b=(struct employee*)malloc(sizeof(struct employee));
printf("\nEnter the ID number:");
scanf("%d",&w);
int first=1,last=c,mid;
while(first<=last)
{a=head;
mid=(first+last)/2;
while(a!=NULL)
{if(a->index==mid)
{if(a->id==w)
{printf("\nElement found at pos %d, deleted",a->index);
if(a->index==1)
head=head->next;
else
{
b->next=a->next;
}
/*b=head;
while(b->next->id!=w) //not able to put this while to findprev, throwing errors
b=b->next;
b->next=a->next;
*/
found=1;
break;
}
else if(w>(a->id))
{ first=mid+1;
break;
}
else
{
last=mid-1;break;
}
}
b=a;
a=a->next;
}
if(found==1)
break;
}
}
#endif