This file contains 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
#include <iostream> | |
#include <vector> | |
template<class T> | |
void merge(std::vector<T>& vals, int l, int m, int r) { | |
//iterate through both left and right partitions, selecting | |
//the lowest value of each comparision. | |
std::vector<T> out; | |
int i=l, j=m; | |
while(out.size() <= r-l) { |
This file contains 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
#include <iostream> | |
#include <vector> | |
void merge(std::vector<int>& nums, int start, int chunk_size) { | |
//iterate through first partition (start -> start+chunk_size) while | |
//iterating through second partition and choose the smallest number | |
std::vector<int> result; | |
int mid = start + (chunk_size); | |
int merge_size = chunk_size*2; | |
for (int i=start,j=mid; result.size()<merge_size; ) { |
This file contains 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
#include <iostream> | |
#include <vector> | |
template <class T> | |
void bubble_sort(std::vector<T>& vals) | |
{ | |
bool bMadeSwap = true; | |
while (bMadeSwap) { | |
bMadeSwap = false; | |
for (int i=0; i<vals.size()-1; i++) { |
This file contains 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
#include <iostream> | |
#include <vector> | |
template <class T> | |
int partition(std::vector<T>& vals, int l, int r) { | |
int i=l-1, j=r, v=vals[r]; | |
for (;;) { | |
while (vals[++i] < v) ; | |
while (vals[--j] > v) if (j<1) break; | |
if (i>=j) break; |
This file contains 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
#include <iostream> | |
#include <vector> | |
#include <stack> | |
template <class T> | |
int partition(std::vector<T>& vals, int l, int r) { | |
int i=l-1, j=r, v=vals[r]; | |
for (;;) { | |
while (vals[++i] < v) ; | |
while (vals[--j] > v) if (j<1) break; |
This file contains 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
#include <iostream> | |
#include <vector> | |
template <class T> | |
class MinHeap | |
{ | |
private: | |
std::vector<T> m_vals; | |
public: |
This file contains 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
<html> | |
<body> | |
<canvas id="spiral" width="800" height="600"> | |
</canvas> | |
<script> | |
function drawSpiral() { | |
var canvas = document.querySelector('#spiral'); | |
var ctx = canvas.getContext('2d'); | |
var i = 0, j=0, k=1; | |
var x = 200, y=200; |
This file contains 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
#include <iostream> | |
#include <vector> | |
#include <unordered_map> | |
struct edge { | |
int target; | |
int weight; | |
}; | |
typedef std::unordered_multimap<int, edge> vertices; |
This file contains 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
#include <iostream> | |
#include <vector> | |
struct edge { | |
int src; | |
int dst; | |
int weight; | |
}; | |
std::vector<int> bellmanford(const std::vector<edge>& edges, int num_verts) { |
This file contains 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
#include <iostream> | |
#include <vector> | |
struct edge { | |
int src; | |
int dst; | |
int weight; | |
}; | |
struct vertex { |
OlderNewer