📄 可可.txt
字号:
// sdf.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream.h>
//#define null 0
struct File
{
char name;
int len;
int blockNum;
File * next;
};
int M,N,K;
int * chart;
File * head;//,* tail;
void init();
void create();
void del();
void display();
int main(int argc, char* argv[])
{
cout << "输入柱面数,磁道数,扇区数:";
cin >> M >> N >> K;
chart = new int[M*N*K];
for(int i = 0; i < M*N*K; i++)
chart[i] = 0;
init();
int cc;
cout << "请选择:\n1.分配2.删除3.显示0.退出\n";
cin >> cc;
while(cc)
{
switch(cc)
{
case 1:create();display();break;
case 2:del();display();break;
case 3:display();break;
case 0:break;
}
cout << "请选择:\n1.分配2.删除3.显示0.退出\n";
cin >> cc;
}
return 0;
}
void init()
{
head = new File;//tail = new File;
(*head).next = NULL;//(*tail).next = null;
}
void create()
{
File * temp = new File;
cout << "输入新建文件名及长度:";
cin >> (*temp).name >> (*temp).len ;
(*temp).next = NULL;
int num = 0;
for(int i = 0; i < M*N*K;)
{
if(chart[i++] == 0)
{
num ++;
if(num == (*temp).len)
{
(*temp).blockNum = i - num;
//File * p = &temp;
for(int j = 0; j < (*temp).len; j++)
{
chart[(*temp).blockNum + j] = 1;
}
if((*head).next != NULL)
{
(*temp).next = (*head).next;
(*head).next = temp;
//(*tail).next = p;
//tail = p;
return;
}
else
{
(*head).next = temp;
return;
}
}
}
else
{
num = 0;
}
}
cout << "分配失败...........\n";
}
void del()
{
char ch;
cout << "输入要删除的文件名:";
cin >> ch;
File * temp = (*head).next;
File * p = head;
cout << "输入要删除的文件名:";
while(temp != NULL)
{
if((*temp).name == ch)
{
for(int i = 0; i < (*temp).len;i++)
{
chart[(*temp).blockNum + i] = 0;
}
(*p).next = (*temp).next;
//delete temp;
return;
}
else
{
p = temp;
temp = (*temp).next;
}
}
}
void display()
{
cout << "位示图:\n";
for(int i = 0; i < M; i++)
{
for(int j = 0; j < M*K; j++)
{
cout << chart[i*M*K + j];
}
cout << endl;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -