Output: 7 5 3 1 2 6 16 24 24
Ford Tesla BMW Toyota
public int diff(LinkedStack<T> two) { int numDiff = 0; LLNode<T> temp = top; LLNode<T> tempTwo = two.top; while (temp != null && tempTwo != null) { if (temp.getInfo().equals(tempTwo.getInfo()) numDiff++; temp = temp.getLink(); tempTwo = tempTwo.getLink(); } if (temp != null) while (temp != null) { numDiff++; temp = temp.getLink(); } if (tempTwo != null) while (tempTwo != null) { numDiff++; tempTwo = tempTwo.getLink(); } return numDiff; }
public String toString() { return title + " " + studio + " " + genre + " " + length + " minutes"; }
public boolean isGenre(String gen) { if (genre.equals(gen)) return true; else return false; }
ArrayBoundedStack<Film> action = new ArrayBoundedStack<>(); ArrayBoundedStack<Film> comedy = new ArrayBoundedStack<>();
int i; String title, studio, genre, dummy; int length; Film inFilm; System.out.println("enter the title of the film: "); title = keybd.nextLine(); while (!title.equals("done")) { System.out.println("enter the studio name: "); studio = keybd.nextLine(); System.out.println("enter the genre: "); genre = keybd.nextLine(); System.out.println("enter the length of the film: "); length = keybd.nextInt(); dummy = keybd.nextLine(); inFilm = new Film(title, studio, genre, length); if (inFilm.isGenre().equals("action")) action.push(inFilm); if (inFilm.isGenre().equals("comedy")) comedy.push(inFilm); System.out.println("enter the title of the film: "); title = keybd.nextLine(); }
while (!action.isEmpty()) { inFilm = action.top(); action.pop(); System.out.println(inFilm); }
while (!comedy.isEmpty()) { inFilm = comedy.top(); comedy.pop(); System.out.println(inFilm); }
public static int numOver(int[] arr, int size) { if (size == 0) return 0; else { if (arr[size-1] > 100) return 1 + numOver(arr,size-1); else return numOver(arr,size-1); } }
Email Me |
Office Hours |
My Home Page |
Department Home |
MCC Home Page
© Copyright Emmi Schatz 2023