-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDriver_alt.java
More file actions
66 lines (64 loc) · 2.36 KB
/
Driver_alt.java
File metadata and controls
66 lines (64 loc) · 2.36 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
import java.util.Scanner;
import java.io.File;
import java.io.IOException;
public class Driver_alt {
public static void printarray(A1DynamicMem fox) {
//Dictionary free1 = fox.freeBlk.getFirst();
//Dictionary alloc1 = fox.allocBlk.getFirst();
for (Dictionary d = fox.freeBlk.getFirst(); d != null; d = d.getNext()) {
System.out.print(d.address + " ");
System.out.print(d.address + d.size + " ");
//System.out.print(d.key + " ");
System.out.print(" ");
}
System.out.println(" ");
for (Dictionary d = fox.allocBlk.getFirst(); d != null; d = d.getNext()) {
System.out.print(d.address + " ");
System.out.print(d.address + d.size + " ");
//System.out.print(d.key + " ");
System.out.print(" ");
}
System.out.println("");
System.out.println("");
}
public static void main(String args[]) throws IOException{
File myObj = new File("./test.in.txt");
//File r=new File("./ans2.txt");
//Scanner s= new Scanner(r);
Scanner sc = new Scanner(myObj);
int numTestCases,c=0;
numTestCases = sc.nextInt();
while (numTestCases-- > 0) {
int size;
size = sc.nextInt();
A1DynamicMem obj = new A1DynamicMem(size,1);
int numCommands = sc.nextInt();
while (numCommands-- > 0) {
String command;
command = sc.next();
int argument;
argument = sc.nextInt();
int result = -5;
switch (command) {
case "Allocate":
result = obj.Allocate(argument);
break;
case "Free":
result = obj.Free(argument);
break;
default:
break;
}
//int t=s.nextInt();
//if(t!=result)
//c++;
//System.out.println(result+ " "+c+" "+t);
System.out.println(result);
//System.out.println(command+" "+argument+":"+result);
//printarray(obj);
}
}
sc.close();
// s.close();
}
}