Account Comparator By Name public class Account Comparator
Account. Comparator. By. Name המחלקה public class Account. Comparator. By. Name implements Comparator<Bank. Account>{ //Complete the following method public int compare(Bank. Account account 1, Bank. Account account 2) { } } © 2018 מבוא למדעי המחשב Implement the class Account. Comparator. By. Name so that it will compare objects of type Bank. Account according to their names. 2
נוסף stack בעזרת stack מיון public static<T> Stack<T> sort. Stack(Stack<T> input. Stack, Comparator<T> c) { Stack<T> tmp. Stack = new Stack. As. Dynamic. Array<T>(); // complete code } © 2018 מבוא למדעי המחשב Given a stack of type T, sort it in descending order using another temporary stack, by using the following algorithm: 1. Create a temporary stack called tmp. Stack 2. While input stack is not empty do this: - Pop on element from input stack and call it tmp - while tmp. Stack is not empty and top of tmp. Stack is greater than tmp: - pop from tmp. Stack and push it to the input stack - push tmp in tmp. Stack 3. return tmp. Stack 3
איטרטור של מספרים טבעיים public class Natural. Number. Iterator implements Iterator<Integer> { private int next. Number; // the next number to return always sits ready in this field private int max. Number; // never give a larger number than this one Implement an iterator of natural numbers, so that each call to next() will return the next natural number, starting from 0 and stopping at max. Number. public Natural. Number. Iterator(int max. Number){ } public boolean has. Next(){ } public Integer next(){ } } © 2018 מבוא למדעי המחשב 4
הדפסת זוגות מספרים public static void print. All. Pairs(int n) { } Use the Natural. Number. Iterator in order to print all pairs of natural numbers up to n, with each pair separated by parentheses. For example, the call print. All. Pairs(2) will print: (0, 0) (0, 1) (0, 2) (1, 0) (1, 1) (1, 2) (2, 0) (2, 1) (2, 2) © 2018 מבוא למדעי המחשב 5
- Slides: 5