Skip to content

Commit

Permalink
time for selectionsort
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarneiva committed Oct 25, 2019
1 parent 3b3fa06 commit e56fbda
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
Binary file modified build/classes/algorithms/SelectionSort.class
Binary file not shown.
21 changes: 15 additions & 6 deletions src/algorithms/SelectionSort.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public SelectionSort(){
// Sorts the array
public void sort(int array[]){
System.out.println("Sorting the array...");
double startTime = System.nanoTime();
int n = array.length;

for (int i = 0; i < n-1; i++){
Expand All @@ -33,8 +34,10 @@ public void sort(int array[]){
array[i] = temp;
}

System.out.println("Array sorted!");
printArray(array);
double endTime = System.nanoTime();
double time = (endTime - startTime)/Math.pow(10, 9);
System.out.println("Array Sorted! Time: " + time + " seconds.");
//printArray(array);
}

// Prints the array
Expand All @@ -49,6 +52,7 @@ void printArray(int array[]){
// Sorts the list
public void sort(LinkedList<Integer> list){
System.out.println("Sorting the list...");
double startTime = System.nanoTime();
int n = list.size();

for (int i = 0; i < n-1; i++){
Expand All @@ -64,8 +68,10 @@ public void sort(LinkedList<Integer> list){
list.set(i, temp);
}

System.out.println("List sorted!");
printList(list);
double endTime = System.nanoTime();
double time = (endTime - startTime)/Math.pow(10, 9);
System.out.println("List Sorted! Time: " + time + " seconds.");
//printList(list);
}

// Prints the list
Expand All @@ -80,6 +86,7 @@ void printList(LinkedList<Integer> list){
// Sorts the stack
public void sort(Stack<Integer> stack){
System.out.println("Sorting the stack...");
double startTime = System.nanoTime();
int n = stack.size();

for (int i = 0; i < n-1; i++){
Expand All @@ -95,8 +102,10 @@ public void sort(Stack<Integer> stack){
stack.set(i, temp);
}

System.out.println("Stack sorted!");
printStack(stack);
double endTime = System.nanoTime();
double time = (endTime - startTime)/Math.pow(10, 9);
System.out.println("Stack Sorted! Time: " + time + " seconds.");
//printStack(stack);
}

// Prints the stack
Expand Down

0 comments on commit e56fbda

Please sign in to comment.