-
- Notifications
You must be signed in to change notification settings - Fork 359
Added Processing language + BogoSort implementation #436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
bcd6a56
52e4c29
3cee797
782cbc1
7bfb564
301f188
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
| @@ -139,6 +139,10 @@ | |
{ | ||
"lang": "f90", | ||
"name": "Fortran90" | ||
}, | ||
{ | ||
"lang": "processing", | ||
"name": "Processing" | ||
} | ||
] | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
int[] test_array = new int[5]; | ||
| ||
void setup() { | ||
size(400,400); | ||
stroke(255); | ||
fill(0); | ||
| ||
random_array(test_array,0,100); | ||
} | ||
| ||
void draw(){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dumb question about processing. Does everything require a visual output? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not a requirement but Processing language was created for that kind of task. | ||
background(255); | ||
| ||
int w = width/test_array.length , minimum = min(test_array) , maximum = max(test_array); | ||
for(int i=0;i<test_array.length;i++){ | ||
rect(w*i,height,w,-map(test_array[i],minimum,maximum,5,height-5)); | ||
} | ||
| ||
if (isSorted(test_array)){ | ||
noLoop(); | ||
println("Finished in "+ millis()/1000 +" seconds."); | ||
}else{ | ||
randomize(test_array); | ||
} | ||
} | ||
| ||
| ||
void random_array(int[] array , int min , int max){ | ||
for(int i=0;i<array.length;i++){ | ||
array[i] = (int) random(min,max); | ||
} | ||
} | ||
| ||
void swap(int[] array, int i, int j) { | ||
int temp = array[i]; | ||
array[i] = array[j]; | ||
array[j] = temp; | ||
} | ||
| ||
| ||
void randomize(int[] array) { | ||
johhnry marked this conversation as resolved. Show resolved Hide resolved | ||
for (int i = array.length-1; i>=1 ; i--) { | ||
int j = (int) random(0, i); | ||
swap(array,i,j); | ||
} | ||
} | ||
| ||
Boolean isSorted(int[] array){ | ||
for(int i=0;i<array.length-1;i++){ | ||
if (array[i]>array[i+1]) return false; | ||
} | ||
return true; | ||
} | ||
| ||
void bogo_Sort(int[] array){ | ||
| ||
while (! isSorted(array)){ | ||
randomize(array); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
lang
should be the file extension, which ispde
in this case.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes you are right, do I need to change that in the Pull request?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@johhnry Yep. Just push your changes to the branch you made this PR from.