-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsequence.c
More file actions
207 lines (184 loc) · 3.66 KB
/
sequence.c
File metadata and controls
207 lines (184 loc) · 3.66 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct file{
char name[10];
int start;
int size;
int status;
}f[10];
struct node
{
int info;
char a[10];
struct node *next;
struct node *prev;
}*start,*temp,*new,*t,*s;
int fno=1,sz,st,fb=0;
char fn[10];
char name[10];
int size,d;
int i,ch;
void createBlock()
{
printf("Enter the total block of Disk : ");
scanf("%d",&d);
start=temp=NULL;
for(i=0;i<d;i++)
{
new=(struct node*)malloc(sizeof(struct node));
new->next=NULL;
new->prev=NULL;
strcpy(new->a,"F");
new->info=i;
if(start==NULL)
{
start=temp=new;
}
else
{
new->prev=temp;
temp->next=new;
temp=new;
}
}
}
void contain()
{
temp =start;
while(temp!=NULL)
{
printf("%d \t",temp->info );
temp=temp->next;
}
temp=start;
printf("\n");
while(temp!=NULL)
{
printf("%s \t ",temp->a);
temp=temp->next;
}
}
void Add()
{
printf("\n Enter FileName & Size : " ) ;
scanf("%s%d",fn,&sz);
fb=0;
temp=start;
while(temp!=NULL)
{
if (strcmp(temp->a,"A")==0)
{
fb=0;
}
if (strcmp(temp->a,"A")!=0)
{
if(fb==0)
{
s=temp;
fb++;
}
else
fb++;
}
if(fb==sz)
{
break;
}
temp=temp->next;
}
if(fb < sz)
{
printf("\n Inefficient Memory for file %s \n",fn);
fb=0;
}
else
{
fno++;
strcpy(f[fno].name,fn);
f[fno].size=sz;
f[fno].start=s->info;
f[fno].status=1;
}
while(fb>0)
{
strcpy(s->a,"A");
s=s->next;
fb--;
}
}
void Delete()
{
printf(" Enter file name to Delete:");
scanf("%s",fn);
for(i=0;i<=fno;i++)
{
if(strcmp(f[i].name,fn)==0)
{
sz=f[i].size;
st=f[i].start;
f[i].status=0;
f[i].start=1;
break;
}
}
temp=start;
while(temp->next!=NULL)
{
if(temp->info==st)
{
break;
}
else
{
temp=temp->next;
}
}
while(sz>0)
{
strcpy(temp->a,"f");
temp=temp->next;
sz--;
}
}
void files()
{
printf("\n______________________________________________________________\n");
printf("Fname\t Size\t Start\t Status\n");
printf("\n______________________________________________________________\n");
{
for(i=0;i<=fno;i++)
{
if(f[i].status!=0)
printf("%s\t%d\t%d\t%d\n",f[i].name,f[i].size,f[i].start,f[i].status);
}
}
printf("\n______________________________________________________________\n");
}
void main()
{
do
{
printf("\n 1.Create Blocks\n 2.Add\n 3.Delete\n 4.Files\n 5.Contains\n 6.Exit\n");
printf("\n enter Your Choice : ");
scanf("%d",&ch);
switch(ch)
{
case 1:
createBlock();
break;
case 2:
Add();
break;
case 3:
Delete();
break;
case 4:
files();
break;
case 5:
contain();
break;
}
}while(ch!=6);
}