This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Takes in an array that has two sorted subarrays, | |
| // from [p..q] and [q+1..r], and merges the array | |
| var merge = function(array, p, q, r) { | |
| // This code has been purposefully obfuscated, | |
| // as you'll write it yourself in next challenge. | |
| var a=[],b=[],c=p,d,e;for(d=0;c<=q;d++,c++){a[d]=array[c];}for(e=0;c<=r;e++,c++){b[e]=array[c];}c=p;for(e=d=0;d<a.length&&e<b.length;){if(a[d]<b[e]){array[c]=a[d];d++;} else {array[c]=b[e]; e++;}c++; }for(;d<a.length;){array[c]=a[d];d++;c++;}for(;e<b.length;){array[c]=b[e];e++;c++;} | |
| }; | |
| // Takes in an array and recursively merge sorts it |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Takes in an array that has two sorted subarrays, | |
| // from [p..q] and [q+1..r], and merges the array | |
| var merge = function(array, p, q, r) { | |
| var lowHalf = []; | |
| var highHalf = []; | |
| var k = p; | |
| var i; | |
| var j; | |
| for (i = 0; k <= q; i++, k++) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // This function partitions given array and returns | |
| // the index of the pivot. | |
| var partition=function(array, p, r){ | |
| // This code has been purposefully obfuscated, | |
| // as you will implement it yourself in next challenge | |
| var e=array,t=p,n=r;var r=function(e,t,n){var r=e[t];e[t]=e[n];e[n]=r;};var i=t;for(var s=t;s<n;s++){if(e[s]<=e[n]){r(e,s,i);i++;}}r(e,n,i);return i; | |
| }; | |
| var quickSort = function(array, p, r) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Swaps two items in an array, changing the original array | |
| var swap = function(array, firstIndex, secondIndex) { | |
| var temp = array[firstIndex]; | |
| array[firstIndex] = array[secondIndex]; | |
| array[secondIndex] = temp; | |
| }; | |
| var partition = function(array, p, r) { | |
| // Compare array[j] with array[r], for j = p, p+1,...r-1 | |
| // maintaining that: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var edgeList = [ [0, 2], [1, 3], [2, 3], [2, 4], [3, 5], [4, 5] ]; | |
| var adjMatrix = [ | |
| [0, 0, 1, 0, 0, 0], | |
| [0, 0, 0, 1, 0, 0], | |
| [0, 0, 0, 1, 1, 0], | |
| [0, 0, 0, 0, 0, 1], | |
| [0, 0, 0, 0, 0, 1], | |
| [0, 0, 0, 0, 0, 0], | |
| ]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* A Queue object for queue-like functionality over JavaScript arrays. */ | |
| var Queue = function() { | |
| this.items = []; | |
| }; | |
| Queue.prototype.enqueue = function(obj) { | |
| this.items.push(obj); | |
| }; | |
| Queue.prototype.dequeue = function() { | |
| return this.items.shift(); | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| background(186, 145, 20); // wooden table | |
| ellipse(200, 200, 350, 350); // plate | |
| ellipse(200, 200, 300, 300); | |
| fill(255, 0, 0); strokeWeight(20); | |
| fill(255, 0, 94); | |
| stroke(44, 153, 44); | |
| arc(200, 250, 200, 175, 5, 180); //watermelon | |
| fill(32, 140, 32); | |
| noStroke(); | |
| ellipse(200, 100, 10,10); //peas |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| rect(5,200,400,200); | |
| ellipse(200, 300, 150, 150); | |
| ellipse(200, 200, 100, 100); | |
| ellipse(200, 120, 75, 75); | |
| line(160,200,50,50); | |
| line(240,200,50,150); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var x = 200; | |
| var y = 250; | |
| noStroke(); | |
| fill(30, 204, 91); // a nice froggy green! | |
| ellipse(x, y, 200, 100); // face | |
| ellipse(x - 50, y - 50, 40, 40); // left eye socket | |
| ellipse(x + 50, y - 50, 40, 40); // right eye socket | |
| ellipse(x,y,20,60); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| noStroke(); | |
| var leftX = 153; | |
| var rightX = 222; | |
| var sunRadius = 100; | |
| draw = function() { | |
| background(184, 236, 255); | |
| fill(255, 170, 0); | |
| ellipse(200, 100, sunRadius+=2, sunRadius); |