-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
46c8c49
commit 3dc1aa1
Showing
17 changed files
with
582 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** | ||
* @author Li Zezhong | ||
* @create 2021-12-16 19:07 | ||
*/ | ||
public interface Hight_order_fun { | ||
public int apply(int x); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** | ||
* @author Li Zezhong | ||
* @create 2021-12-17 14:28 | ||
*/ | ||
public interface Ourcomparable<Item> { | ||
public int compareTo(Item o); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import java.util.ArrayList; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
|
||
/** | ||
* @author Li Zezhong | ||
* @create 2021-12-16 16:30 | ||
*/ | ||
|
||
public class lecture4_3 { | ||
public static void main(String[] args){ | ||
Dog[] dogs = new Dog[]{new Dog("Elyse", 3), new Dog("Sture", 9), new Dog("Benjamin", 15)}; | ||
max(dogs).bark(); | ||
Comparator<Dog> nc = Dog.getNameComparator(); | ||
System.out.println(nc.compare(dogs[0],dogs[2])); | ||
} | ||
|
||
public static Dog max(Dog[] items){ | ||
int maxDex = 0; | ||
for (int i = 0; i < items.length; i += 1) { | ||
int cmp = items[i].compareTo(items[maxDex]); | ||
if (cmp > 0) { | ||
maxDex = i; | ||
} | ||
} | ||
return items[maxDex]; | ||
} | ||
|
||
public static void getWords(String inputFileName){ | ||
List<String> lst = new ArrayList<String>(); | ||
In in = new In(); | ||
|
||
} | ||
} | ||
|
||
class Dog implements Comparable<Dog>{ | ||
private String name; | ||
private int size; | ||
|
||
public Dog(String n, int s) { | ||
name = n; | ||
size = s; | ||
} | ||
|
||
public void bark() { | ||
System.out.println(name + " says: bark"); | ||
} | ||
|
||
@Override | ||
public int compareTo(Dog o) { | ||
return this.size - o.size; | ||
} | ||
|
||
private static class NameComparator implements Comparator<Dog> { | ||
|
||
@Override | ||
public int compare(Dog o1, Dog o2) { | ||
return o1.name.compareTo(o2.name); | ||
} | ||
} | ||
|
||
public static Comparator<Dog> getNameComparator() { | ||
return new NameComparator(); | ||
} | ||
} | ||
|
Oops, something went wrong.