Output: 9 4 8 17 25 32 32
cello bass flute oboe
public boolean same(LinkedStack<T> two) { LLNode<T> temp = top; LLNode<T> tempTwo = two.top; boolean equal = true; while (temp != null && tempTwo != null) { if (!temp.getInfo().equals(tempTwo.getInfo()) equal = false; temp = temp.getLink(); tempTwo = tempTwo.getLink(); } if (temp == null && tempTwo != null) equal = false; if (temp != null && tempTwo == null) equal = false; return equal; }
public String toString() { String disk = manufacturer + " " + model + " "; if (mag) disk = disk + "magnetic " + size + "GB"; else disk = disk + "SSD " + size + "GB"; return disk; }
public boolean isMagnetic() { return mag; }
ArrayBoundedStack<Disk> magStack = new ArrayBoundedStack<>(); ArrayBoundedStack<Disk> SSDStack = new ArrayBoundedStack<>();
int i; String mfg, model, mag, dummy; int size; Disk disk; System.out.println("enter disk manufacturer: "); mfg = keybd.nextLine(); while (!mfg.equals("done")) { System.out.println("enter disk model: "); model = keybd.nextLine(); System.out.println("enter disk type (magnetic or SSD): "); mag = keybd.next(); System.out.println("enter disk size in GB: "); size = keybd.nextInt(); dummy = keybd.nextLine(); if (mag.equals("magnetic")) disk = new Disk(mfg, model, true, size); else disk = new Disk(mfg, model, false, size); if (disk.isMagnetic()) magStack.push(disk); else SSDStack.push(disk); System.out.println("enter disk manufacturer: "); mfg = keybd.nextLine(); }
while (!magStack.isEmpty()) { disk = magStack.top(); magStack.pop(); System.out.println(disk); } while (!SSDStack.isEmpty()) { disk = SSDStack.top(); SSDStack.pop(); System.out.println(disk); }
public static int lower(int[] arr, int size, int value) { if (size == 0) return 0; else { if (arr[size-1] < value) return 1 + lower(arr, size-1, value); else return lower(arr, size-1, value); } }
Email Me |
Office Hours |
My Home Page |
Department Home |
MCC Home Page
© Copyright Emmi Schatz 2023