We are about to switch to a new forum software. Until then we have removed the registration on this forum.
(This may seem a little basic but..) I want to create an array with a random size and filled with random integers between 1 and 100. I then want to be able to sort them using bubble sort. I'm really stuck and would appreciate if someone could point me in the right direction. here's what I have so far but it prints out some crazy answers.
float [] array = new float [100]; float temp = 0; void setup() { for (int a = 0; a< array.length; a++) { array[a]= int(random (10, 100)); } } void draw () { for (int s =0; sarray[d+1]) { temp = array[d+1]; array[d+1] =temp; } } } println( array);
Answers
https://forum.Processing.org/two/discussion/8045/how-to-format-code-and-text
https://Processing.org/reference/sort_.html
Apologies about code formatting should look easier on the eye now
If you want to have integers, you should use an int-array instead of float.
If you want an array of random-size, you should not initialize one with a length of 100.
You fill the array with random numbers between 10 and 100 instead of 1 and 100.
You should move you sorting-algorithm to setup(), it makes no sense to repeat this step. Once the array is sorted, it would not change anymore.
The syntax of your second for-loop is wrong, look at your first one to see how it should look like.
The println(array);
is outside of any function, that will throw an error, move it to setup() too.So your code could look kind of like this:
I left the sorting part out, so you can try to solve it on your own. If you need more information on bubble-sort, wikipedia is a nice source.
OMG YES Thank you soon much!!!!!!!!