Writing mock disk defragmentation method using arrays, shuffling them across

793 Views Asked by At

So I'm trying to write a disk defragmentation method using arrays, one array the File allocation table this acting as a linked list for the data blocks, and one referring to the actual data, although there is no data inside them just integer values. My current idea is to copy all the values into an ArrayList and then write back to the array to shuffle the "Blocks" across, here is what I have so far:

import java.util.ArrayList;
public class Main {
    static int FAT[]            = new int[16]; // File allocation table
    static int dataBlocks[]     = new int[16]; // Datablocks although these represent random values
    static int diskBlocks = 16; // amount of disblocks
    static int dataEnd    = -5;
    static ArrayList<Integer> t = new ArrayList<Integer>(); // temporary array
    public static void main(String args[]){
        for( int i = 0; i< 16; i++){
            FAT[i]  = i+1;  // this referes to the next value in the list
            dataBlocks[i] = i;
            t.add(FAT[i]);  //add the values to a temporary array
            if(i == 10){
                FAT[i + 1] = dataEnd;
                t.set(i, dataEnd);
            }
        }
    }
}

So far I'm just adding the values to the Arrays/the Arraylist I want to use to copy them across, now i just need to shuffle them across to make a disk defrag method.

0

There are 0 best solutions below