-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.c
More file actions
145 lines (126 loc) · 1.49 KB
/
index.c
File metadata and controls
145 lines (126 loc) · 1.49 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
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include<stdio.h>
struct node
{
int data;
struct node*next;
}*newnode,*temp,*start,*temp1;
int m,n,i,x,no,a;
int dir[10][2];
a=0;
void create()
{
i=0;
start=NULL;
while(i!=n)
{
newnode=(struct node*)malloc(sizeof(struct node));
newmode->next=NULL;
newnode->data=-1;
if(start==NULL)
start=temp=newnode;
else
{
temp->next=newnode;
temp=newnode;
}
i++;
}
}
void allocate()
{
int cnt=1;
int count=0;
temp1=start;
if(temp1->data==-1)
{
if(m<n)
{
temp1->data=cnt;
temp1=temp->next;
for(i=1;i<m-1;i++)
{
temp1->data=0;
temp1=temp1->next;
}
temp1->data=-2;
dir[a][0]=no;
dir[a][1]=cnt;
a++;
}
else
{
printf("lock can not be allocated");
exit(0);
}
}
else
{
printf("\n Block can not allocated");
exit(0);
}
}
else
{
while(temp1->data!=-1)
{
temp1=temp1->next;
count++;
cnt++;
}
if(m+count <=n)
{
temp1->data=cnt;
for(i=1;i<m-1;i++)
{
temp1=temp1->next;
temp1->data=0;
}
temp1=temp1->next;
temmp1->data=-2;
dir[a][0]=no;
dir[a][1]=cnt;
a++;
}
else
{
printf("\nBlocks can not be allocated");
exit(0);
}
}
void deallocate()
{
int bno,j;
int count=1;
temp1=start;
for(j=0;j<10;j++)
{
if(dir[j][0]==x)
{
bno=dir[i][1];
dir[j][0]=0;
dir[j][1]=0;
break;
}
}
while(count!=bno)
{
count++;
temp1=temp1->next;
}
while(temp1->data!=-2)
temp1->data = -1;
temp1=temp1->next;
}
void display()
{ int tot=0;
temp1=start;
while(temp1!=NULL)
{
printf("%d\t",temp1->data);
if(temp1->data==-1)
tot++;
temp1=temp1->next;
printf("\nTotal allocated block are %d",n-tot);
printf("\n Total free blocks are %d\n",tot);
for(i=0;i<10;i++)
{