User Tools

Site Tools


spcs:2015:day4

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
spcs:2015:day4 [2015/07/08 21:56]
ffpaladin
spcs:2015:day4 [2015/07/09 00:13]
ffpaladin
Line 208: Line 208:
   }   }
 } }
 +
 +</​code>​
 +
 +<code java>
 +
 +int[] cheesesticks = {200, 40, 170, 50, 70, 60, 80, 90, 190, 150, 100, 110, 120, 140, 180, 130, 20, 160, 30, 10};
 +
 +int i = -1;
 +int j = 0;
 +int min;
 +
 +void setup() {
 +  size (250, 250);
 +}
 +
 +void draw() {
 +  ​
 +  background(200);​
 +  ​
 +  // only runs after j reaches 20  ​
 +  if ((j == 20) && (i < 19)) {
 + 
 +     i++;
 +     ​j=i+1;​
 +     min = cheesesticks[i];​
 +  }
 + 
 +  // runs as long as j is less than 20
 +  if (j < 20) {
 + 
 +    if (cheesesticks[j] < min){
 +      min = cheesesticks[j];​
 +      //swap
 +      int temp = cheesesticks[i];​
 +      cheesesticks[i] = cheesesticks[j];​
 +      cheesesticks[j] = temp;
 +    }
 +    j++;
 +  }
 +  ​
 +  fill(#​EA5353);​
 +
 +for (int i=0; i<20; i++)
 +  {
 +    rect(0, i*10,​cheesesticks[i],​ 5);
 +  }
 +
 +
  
 </​code>​ </​code>​
  
/soe/sherol/.html/teaching/data/pages/spcs/2015/day4.txt · Last modified: 2015/07/09 05:26 by ffpaladin