homework:Bankers Algorithm,read matrix txt file

1.5k Views Asked by At

Bankers algorithm: I am trying to read from txt file into 4 variables. allocation,Max matrix/ available and request vectors. i am stuck as to how to read it properly. The txt file first value is number of process and 2nd value is resources, the first matrix is allocation and 2nd matrix is Max, then lastly 2 vectors.this is what i have so far

this is the txt file:

5

4

0 0 1 2
1 0 0 0
1 3 5 4
0 6 3 2
0 0 1 4

0 0 1 2
1 7 5 0
2 3 5 6
0 6 5 2
0 6 5 6

1 5 2 0

1:0 4 2 0

#include <stdio.h>
#include <fstream>
#include <vector>


int main(int argc, char *argv[])
{
ifstream mFile;
mFile.open("s1.txt");
vector<int> request[],available[];
int allocation[][],Max[][];
int m,n;
vector <int> work,finish;
work = available;

mFile >>m >>n;
while(!mFile.eof())
{

for(int i=0; i< m; i++)
{
for(int j =0;j<n;j++)
{
    mFile >> allocation[i][i];
    mFile >> Max[i][j];
    request[i][j] = Max[i][j] - allocation[i][j];

}
} 
}   


mFile.close();
}
1

There are 1 best solutions below

2
On

Where to start: without searching too far I can see:

vector<int> need[][],available[];

What is need?, a 2D array of int vectors with 0 size ?

You use variable m and n, but I don't see them defined or declared.