Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
vijaygarg1 committed Jan 23, 2018
1 parent 50245f8 commit 3a61e97
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
12 changes: 12 additions & 0 deletions hw1-template/PMerge.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//UT-EID=


import java.util.*;
import java.util.concurrent.*;


public class PMerge{
public static void parallelMerge(int[] A, int[] B, int[]C, int numThreads){
// TODO: Implement your parallel merge function
}
}
11 changes: 11 additions & 0 deletions hw1-template/PSort.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//UT-EID=


import java.util.*;
import java.util.concurrent.*;

public class PSort{
public static void parallelSort(int[] A, int begin, int end){
// TODO: Implement your parallel sort function
}
}
54 changes: 54 additions & 0 deletions hw1-template/SortTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import java.util.Arrays;

public class SortTest {
public static void main (String[] args) {
int[] A1 = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
verifyParallelSort(A1);

int[] A2 = {1, 3, 5, 7, 9};
verifyParallelSort(A2);

int[] A3 = {13, 59, 24, 18, 33, 20, 11, 11, 13, 50, 10999, 97};
verifyParallelSort(A3);
}

static void verifyParallelSort(int[] A) {
int[] B = new int[A.length];
System.arraycopy(A, 0, B, 0, A.length);

System.out.println("Verify Parallel Sort for array: ");
printArray(A);

Arrays.sort(A);
PSort.parallelSort(B, 0, B.length);

boolean isSuccess = true;
for (int i = 0; i < A.length; i++) {
if (A[i] != B[i]) {
System.out.println("Your parallel sorting algorithm is not correct");
System.out.println("Expect:");
printArray(A);
System.out.println("Your results:");
printArray(B);
isSuccess = false;
break;
}
}

if (isSuccess) {
System.out.println("Great, your sorting algorithm works for this test case");
}
System.out.println("=========================================================");
}

public static void printArray(int[] A) {
for (int i = 0; i < A.length; i++) {
if (i != A.length - 1) {
System.out.print(A[i] + " ");
} else {
System.out.print(A[i]);
}
}
System.out.println();
}
}

0 comments on commit 3a61e97

Please sign in to comment.