how to sort an array without using the sort method from the collection

0 odirile matlhape · November 2, 2014
Copy the following code into eclipse and complete it. Complete the imple- mentation of the two methods de?ned in the class. Also pay attention to the TODO parts in the main method.
package iss211.lab8;
import java.util.ArrayList;
import java.util.List;
public class Lab8<T extends Comparable<T>> {
public static void main(String[] args) {
Lab8 lab = new Lab8();
int[] a = new int[20];
for(int i = 0; i < 20; i++){ a = (int) (Math.random()*35); }
for(int i = 0; i < 20; i++){ System.out.println(a); }
// TODO: call the method to sort array
System.out.println("\nSorted array");
for(int i = 0; i < 20; i++){ System.out.println(a); }
/******************************************** * Testing list sorting ********************************************/ List<Integer> l = new ArrayList<Integer>(20);
1
for(int i = 0; i < 20; i++){ l.add((int) (Math.random()*35)); }
for(int i = 0; i < 20; i++){ System.out.println(l.get(i).toString()); }
// TODO: call the method for sorting list
System.out.println("\nSorted list");
for(int i = 0; i < 20; i++){ System.out.println(l.get(i).toString()); }
}
/** * Implement the method to sort an array using selection sort. * * @param arr */ public void sortIntArray(int[] arr){
}
/** * * Implement selection sort for a list. * * @param list */ public void sortList(List<T> list){
}
2
}
3

Post a Reply

Replies

Oldest  Newest  Rating
0 Alex Sweps · November 3, 2014
This series covers all of the sorting algorithms. Looks like you need to use an selection sort in there from what I can understand.

https://www.youtube.com/watch?v=P00xJgWzz2c&list=PLAB1DA9F452D9466C
  • 1

Java / Android Development

107,308 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator