-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
queue review & PriorityQueue created
- Loading branch information
Joao Neto
committed
Sep 25, 2023
1 parent
dabc4ac
commit 18d757b
Showing
5 changed files
with
385 additions
and
11 deletions.
There are no files selected for viewing
Binary file not shown.
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,67 @@ | ||
package net.jneto.dataStructures; | ||
|
||
public interface Comparator<ITEM>{ | ||
int compare(ITEM t1, ITEM t2); | ||
} | ||
|
||
/** | ||
* EXAMPLE USAGE - String | ||
* Priority: More length more Priority | ||
*/ | ||
class BiggerStringLengthComparator implements Comparator<String> { | ||
@Override | ||
public int compare(String t1, String t2) { | ||
if (t1.length() < t2.length()) { | ||
return 1; | ||
} else if (t1.length() > t2.length()) { | ||
return -1; | ||
} | ||
return 0; | ||
} | ||
} | ||
/** | ||
* EXAMPLE USAGE - String | ||
* Priority: More length more Priority | ||
*/ | ||
class LessStringLengthComparator implements Comparator<String> { | ||
@Override | ||
public int compare(String t1, String t2) { | ||
if (t1.length() < t2.length()) { | ||
return -1; | ||
} else if (t1.length() > t2.length()) { | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
} | ||
|
||
/** | ||
* EXAMPLE USAGE - Integer | ||
* Priority: Bigger value more Priority | ||
*/ | ||
class BiggerIntegerComparator implements Comparator<Integer> { | ||
@Override | ||
public int compare(Integer t1, Integer t2) { | ||
if (t1 < t2) { | ||
return 1; | ||
} else if (t1 > t2) { | ||
return -1; | ||
} | ||
return 0; | ||
} | ||
} | ||
/** | ||
* EXAMPLE USAGE - Integer | ||
* Priority: Less value more Priority | ||
*/ | ||
class LessIntegerComparator implements Comparator<Integer> { | ||
@Override | ||
public int compare(Integer t1, Integer t2) { | ||
if (t1 < t2) { | ||
return 1; | ||
} else if (t1 > t2) { | ||
return -1; | ||
} | ||
return 0; | ||
} | ||
} |
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
Oops, something went wrong.