Skip to content

Instantly share code, notes, and snippets.

View gcarrillo's full-sized avatar

Erik Gabriel Carrillo gcarrillo

View GitHub Profile
@gcarrillo
gcarrillo / funcptrs.c
Last active August 23, 2018 16:01
Function pointers
#include <stdio.h>
enum ops {
OP_ADD,
OP_SUB,
OP_MULT
};
typedef int (*op_function_t)(int x, int y);
@gcarrillo
gcarrillo / heapsort.py
Last active March 11, 2016 20:29
Heapsort in Python
#!/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]
@gcarrillo
gcarrillo / insertionsort.py
Last active February 16, 2018 19:03
Insertion Sort
#!/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)):
@gcarrillo
gcarrillo / selectionsort.py
Created March 11, 2016 01:56
Selection Sort in Python
#!/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]
@gcarrillo
gcarrillo / mergesort.py
Created March 10, 2016 23:56
Mergesort in Python
#!/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 = []
@gcarrillo
gcarrillo / quicksort.py
Last active March 10, 2016 23:37
Quicksort (Python)
#!/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.
@gcarrillo
gcarrillo / gist:1353454
Created November 9, 2011 22:59
spinner
#! /bin/sh
i=0
echo -n '|'
while true; do
case $i in
0) echo -n '^H|'
;;