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
#include <stdio.h> | |
enum ops { | |
OP_ADD, | |
OP_SUB, | |
OP_MULT | |
}; | |
typedef int (*op_function_t)(int x, int y); | |
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
#!/usr/bin/env python | |
''' | |
Heapsort | |
- Best case: O(n log n) | |
- Average case:O(n log n) | |
- Worst case: O(n log n) | |
''' | |
def swap(l, i, j): | |
tmp = l[i] |
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
#!/usr/bin/env python | |
''' | |
Insertion sort | |
- Best: O(n) | |
- Average: O(n^2) | |
- Worst: O(n^2) | |
''' | |
def insertionsort(l): | |
for i in xrange(0, len(l)): |
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
#!/usr/bin/env python | |
''' | |
Selection sort | |
- Best: O(n^2) | |
- Average: O(n^2) | |
- Worst: O(n^2) | |
''' | |
def swap(l, i, j): | |
tmp = l[i] |
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
#!/usr/bin/env python | |
''' | |
Mergesort | |
- Best: O(n log n) | |
- Average: O(n log n) | |
- Worst: O(n log n) | |
''' | |
def merge(A, B): | |
result = [] |
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
#!/usr/bin/env python | |
''' | |
Quicksort | |
- Best case: O(n log n) | |
- Average case: O(n log n) | |
- Worst case: O(n^2) | |
''' | |
import random | |
random.seed() # Initialize random number generator. |
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
#! /bin/sh | |
i=0 | |
echo -n '|' | |
while true; do | |
case $i in | |
0) echo -n '^H|' | |
;; |