Skip to content

Commit

Permalink
feat(7.5): finish unit 7 lesson 5 activities
Browse files Browse the repository at this point in the history
  • Loading branch information
101zh committed Jan 9, 2024
1 parent e7ec3e4 commit a4fa079
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/main/java/Unit7/U7_L5_Activity_One.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package Unit7;

// Have to get rid of package statement

public class U7_L5_Activity_One {
public static void sortAndPrintReverse(String[] arr) {
for (int i = 0; i < arr.length; i++) {
int high = i;
for (int j = i + 1; j < arr.length; j++) {
if (arr[j].compareTo(arr[high]) > 0) {
high = j;
}
}
String temp = arr[i];
arr[i] = arr[high];
arr[high] = temp;
}

for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + " ");
}
}
}
30 changes: 30 additions & 0 deletions src/main/java/Unit7/U7_L5_Activity_Two.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package Unit7;

// Have to get rid of package statement

import java.util.ArrayList;

public class U7_L5_Activity_Two
{

public static void selectSortReverse(ArrayList<Integer> list){

for(int i=0; i<list.size(); i++){
int largestIndex=i;
for(int j=i+1; j<list.size(); j++){
if(list.get(j)>list.get(largestIndex)){
largestIndex=j;
}
}
int temp = list.get(i);

list.set(i, list.get(largestIndex));
list.set(largestIndex, temp);
}

System.out.println(list);

}

}

0 comments on commit a4fa079

Please sign in to comment.