Week 10 Supplementary Homework

Make up homework after the tenth week of class

1. Summary of relevant knowledge points

  • Comparable interface: If the object stored in the linked list is not string data, the class that creates the object must implement the Comparable interface, that is, implement the method int compareTo(Object b) in the interface to specify the size relationship of the object. That is, let the class of the object to be sorted implement the Comparable interface and override the compareTo() method in the Comparable interface. The disadvantage is that it can only be sorted according to one rule.
  • Comparator interface: Write multiple sorting classes to implement the Comparator interface, and rewrite the compare() method in the new Comparator interface. When calling sort() of Arrays, pass the sorting class object as a parameter: public static void sort(T[ ] a, Comparatorc), sorts the specified array of objects according to the order produced by the specified comparator. All elements in the array must be mutually comparable via the specified comparator (that is, c.compare(e1, e2) must not throw a ClassCastException for any e1 and e2 elements in the array).

2. Make up the content of the class, screenshot of the result

  • Results screenshot

Code cloud link

3. Code Analysis in Chapter 15 of the textbook

4. Make up the programming topics in Chapter 15 of the textbook

  • first sub-question

code link

  • second sub-question

code link

  • third sub-question

code link

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325344180&siteId=291194637