Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions book.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@
{
"lang": "f90",
"name": "Fortran90"
},
{
"lang": "processing",
Copy link
Member

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 is pde in this case.

Copy link
Author

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?

Copy link
Contributor

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.

"name": "Processing"
}
]
}
Expand Down
4 changes: 4 additions & 0 deletions contents/bogo_sort/bogo_sort.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ In code, it looks something like this:
[import:16-18, lang:"nim"](code/nim/bogo_sort.nim)
{% sample lang="ruby" %}
[import:12-16, lang:"ruby"](code/ruby/bogo.rb)
{% sample lang="processing" %}
[import:55-59, lang:"java"](code/processing/bogoSort.pde)
{% endmethod %}

That's it.
Expand Down Expand Up @@ -85,6 +87,8 @@ We are done here!
[import, lang:"nim"](code/nim/bogo_sort.nim)
{% sample lang="ruby" %}
[import, lang:"ruby"](code/ruby/bogo.rb)
{% sample lang="processing" %}
[import:1-53, lang:"java"](code/processing/bogoSort.pde)
{% endmethod %}


Expand Down
59 changes: 59 additions & 0 deletions contents/bogo_sort/code/processing/bogoSort.pde
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(){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dumb question about processing. Does everything require a visual output?

Copy link
Author

Choose a reason for hiding this comment

The 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.
I found it nice to visualize the sorting process.

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) {
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){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like we are mixing camel case and snake case here. We should probably choose one.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to change the code of a pull request?

Copy link
Contributor

@Yordrar Yordrar Oct 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just commit to the branch you have in your forked repo and the PR automatically updates. Read carefully the contributing tutorial!

while (! isSorted(array)){
randomize(array);
}
}