~/appendix/full-code

Appendix B · Full source code.

The full Java implementation, listed in the report as Appendix B. It is pulled directly from the repository’s source folder when the site is built.

15 filesMirrors /src

01Core data structures

Node.java// Singly linked list node · 11 lines
public class Node {    Registration studData; // Field to store Registration data    Node next; // Field to store next Node reference     // Task: Constructor to initialize node with Registration    public Node(Registration studData) {        this.studData = studData;        this.next = null;    } }

02Input & output

03Processing

04Sorting

Sorter.java// Common sorting interface · 5 lines
public interface Sorter {    void sort(Registration[] a);     String name();}
SelectionSort.java// O(n²) · 25 lines
public class SelectionSort implements Sorter {     @Override    public void sort(Registration[] array) {        // Sort in DESCENDING order (highest demand scores first).        for (int i = 0; i < array.length - 1; i++) {            int maxIndex = i; // Assume the current position has the highest score.             for (int j = i + 1; j < array.length; j++) { // Look at all remaining elements to find the actual highest.                if (array[j].getStudDemandScore() > array[maxIndex].getStudDemandScore()) {                    maxIndex = j; // Remember this as the new highest position.                }            }            // Swap            Registration temp = array[i];            array[i] = array[maxIndex];            array[maxIndex] = temp;        }    }     @Override    public String name() {        return "Selection Sort";    }}
InsertionSort.java// O(n²) · O(n) best · 26 lines
public class InsertionSort implements Sorter {     @Override    public void sort(Registration[] array) {        // Start from the second element (index 1).        for (int i = 1; i < array.length; i++) {            Registration current = array[i];            double currentScore = current.getStudDemandScore(); // Get the demand score of the current element for                                                                // comparison.            int j = i - 1; // Start comparing with the element immediately to the left.             // Shift elements that are smaller than current to the right.            while (j >= 0 && array[j].getStudDemandScore() < currentScore) {                array[j + 1] = array[j]; // Shift element to the right.                j--;            }            // Insert current element in correct position.            array[j + 1] = current;        }    }     @Override    public String name() {        return "Insertion Sort";    }}

05Benchmarking & entry point

Timer.java// Millisecond stopwatch · 20 lines
public class Timer {    // Private variables for safety, no other class can access these directly and effect the elapsed time.    private long startTime;    private long endTime;     // Method to start timer    public void start() {        startTime = System.currentTimeMillis(); // Simpler than nanoTime    }     // Method to stop timer    public void stop() {        endTime = System.currentTimeMillis();    }     // Method to get elapsed time in milliseconds    public long getElapsedTimeMillis() {        return endTime - startTime;    }}