diff --git a/README.md b/README.md index 0103fbf..88d36dd 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # lab_bins First example code for refactoring - +I LOVE CATS YAYYY! Making a change!!! Even more changes :) diff --git a/src/Bins.java b/src/Bins.java index b313a3d..acd17d3 100644 --- a/src/Bins.java +++ b/src/Bins.java @@ -37,39 +37,37 @@ public static void main (String args[]) { PriorityQueue pq = new PriorityQueue(); pq.add(new Disk(0)); - int diskId = 1; int total = 0; - for (Integer size : data) { - Disk d = pq.peek(); - if (d.freeSpace() > size) { - pq.poll(); - d.add(size); - pq.add(d); - } else { - Disk d2 = new Disk(diskId); - diskId++; - d2.add(size); - pq.add(d2); - } - total += size; - } - + total = addToDisk(total, pq, data); + System.out.println("total size = " + total / 1000000.0 + "GB"); System.out.println(); - System.out.println("worst-fit method"); - System.out.println("number of pq used: " + pq.size()); - while (!pq.isEmpty()) { - System.out.println(pq.poll()); - } - System.out.println(); + + printQueue(pq, ""); Collections.sort(data, Collections.reverseOrder()); pq.add(new Disk(0)); - diskId = 1; - for (Integer size : data) { + total = addToDisk( total, pq, data); + + System.out.println(); + + printQueue(pq,"decreasing "); + } + public static void printQueue(PriorityQueue pq, String word) { + System.out.println(); + System.out.println("worst-fit " + word + "method"); + System.out.println("number of pq used: " + pq.size()); + while (!pq.isEmpty()) { + System.out.println(pq.poll()); + } + System.out.println(); + } + public static int addToDisk(int total, PriorityQueue pq, List data) { + int diskId = 1; + for (Integer size : data) { Disk d = pq.peek(); - if (d.freeSpace() >= size) { + if (d.freeSpace() >= size) { //one has = one does not, don't know how to fix pq.poll(); d.add(size); pq.add(d); @@ -79,14 +77,8 @@ public static void main (String args[]) { d2.add(size); pq.add(d2); } + total += size; } - - System.out.println(); - System.out.println("worst-fit decreasing method"); - System.out.println("number of pq used: " + pq.size()); - while (!pq.isEmpty()) { - System.out.println(pq.poll()); - } - System.out.println(); + return total; } }