Skip to content

Commit

Permalink
Gitignores changed for some reason. SortSearch updated
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexNPavel committed Apr 29, 2015
1 parent 65b6f38 commit 770aaf0
Show file tree
Hide file tree
Showing 19 changed files with 56 additions and 26 deletions.
1 change: 0 additions & 1 deletion APCompSciStuffSince Oct13/bin/.gitignore

This file was deleted.

1 change: 0 additions & 1 deletion Arraylists/bin/.gitignore

This file was deleted.

1 change: 0 additions & 1 deletion ClassConcepts/bin/.gitignore

This file was deleted.

1 change: 0 additions & 1 deletion ColorProject/bin/.gitignore

This file was deleted.

1 change: 0 additions & 1 deletion ColorProject_01/bin/.gitignore

This file was deleted.

1 change: 0 additions & 1 deletion HeapGame/bin/.gitignore

This file was deleted.

1 change: 0 additions & 1 deletion HeapGame_NoSync/bin/.gitignore

This file was deleted.

1 change: 0 additions & 1 deletion HeapGame_Wait_Notify/bin/.gitignore

This file was deleted.

1 change: 0 additions & 1 deletion Integral Calculator/bin/.gitignore

This file was deleted.

1 change: 0 additions & 1 deletion Integral_Calculator/bin/.gitignore

This file was deleted.

1 change: 0 additions & 1 deletion JavaApplication1/bin/.gitignore

This file was deleted.

2 changes: 0 additions & 2 deletions Matrix/bin/.gitignore

This file was deleted.

2 changes: 0 additions & 2 deletions Midterm/bin/.gitignore

This file was deleted.

1 change: 0 additions & 1 deletion Player/bin/.gitignore

This file was deleted.

1 change: 0 additions & 1 deletion Sep 5/bin/.gitignore

This file was deleted.

1 change: 0 additions & 1 deletion Sep9/bin/.gitignore

This file was deleted.

1 change: 0 additions & 1 deletion SortSearch/bin/.gitignore

This file was deleted.

62 changes: 56 additions & 6 deletions SortSearchClean/src/SortSearch.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class SortSearch {
static long time2;
int tempShift;
boolean reset;
boolean exists;

public SortSearch(int length) {
reset = true;
Expand Down Expand Up @@ -320,7 +321,7 @@ public boolean linearSearch(int[] sortArr, int key) {
}

public boolean binarySearch(int[] sortArr, int key) {
boolean exists = false;
exists = false;
mergeR(sortArr, 0, sortArr.length - 1);
System.out.println("Sorted array is: "+ Arrays.toString(sortArr));
int begin = 0 ;
Expand All @@ -346,6 +347,9 @@ else if (sortArr[mid] > key) {
}

if(!((end - begin) > 0)) {
if (sortArr[begin] == key) {
exists = true;
}
System.out.println("Breaking with begin "+ begin +" and end "+ end);
break;
}
Expand All @@ -354,9 +358,39 @@ else if (sortArr[mid] > key) {
return exists;
}

public void binarySearch(int[] sortArr, int key, int first, int last) {
mergeR(sortArr, 0, sortArr.length - 1);

public boolean binarySearch(int[] sortArr, int key, int first, int last) {
exists = false;
System.out.println("Sorted array is: "+ Arrays.toString(sortArr));
int begin = first ;
int end = last;
int mid = ((end - begin) / 2) + begin;
if(!((end - begin) > 0)) {
if (sortArr[begin] == key) {
exists = true;
}
System.out.println("Breaking with begin "+ begin +" and end "+ end);
return exists;
}
else {
System.out.println("Checking " + sortArr[mid] + " against " + key);
System.out.println("Begin is " + begin + " end is "+ end);
if (sortArr[mid] < key) {
System.out.println("In less than");
begin = mid + 1;
binarySearch(sortArr, key, begin, end);
}
else if (sortArr[mid] > key) {
System.out.println("In greater than");
end = mid - 1;
binarySearch(sortArr, key, begin, end);
}
else {
System.out.println("In exists");
exists = true;
return true;
}
}
return exists;
}

public static void main(String[] args) {
Expand Down Expand Up @@ -486,17 +520,33 @@ public static void main(String[] args) {
// System.out.println("QuickSort "+(time2 - time));
// System.out.println("My sorted array is " + Arrays.toString(myStuff));

int randNum;

// for (int i = 0; i < myStuff.length; i++) {
// myStuff[i] = new Random().nextInt(maxInt);
// }
// System.out.println("Initial array was " + Arrays.toString(myStuff) + "\n");
// randNum = new Random().nextInt(maxInt);
// if (sorter.binarySearch(myStuff, randNum)) {
// System.out.println("Value " + randNum + " exists in array");
// }
// else{
// System.out.println("Value " + randNum + " does not exist in array");
// }

for (int i = 0; i < myStuff.length; i++) {
myStuff[i] = new Random().nextInt(maxInt);
}
System.out.println("Initial array was " + Arrays.toString(myStuff) + "\n");
int randNum = new Random().nextInt(maxInt);
if (sorter.binarySearch(myStuff, randNum)) {
sorter.mergeR(myStuff, 0, myStuff.length - 1);
randNum = new Random().nextInt(maxInt);
if (sorter.binarySearch(myStuff, randNum, 0, myStuff.length - 1)) {
System.out.println("Value " + randNum + " exists in array");
}
else{
System.out.println("Value " + randNum + " does not exist in array");
}

}

}
1 change: 0 additions & 1 deletion TestSenior/bin/.gitignore

This file was deleted.

0 comments on commit 770aaf0

Please sign in to comment.