Skip to content

Instantly share code, notes, and snippets.

View radiofreejohn's full-sized avatar
🤓

John Clover radiofreejohn

🤓
View GitHub Profile
@radiofreejohn
radiofreejohn / btree-norec.c
Created May 27, 2011 16:42
non-recursive binary search tree without return
#include <stdio.h>
#include <stdlib.h>
#include "numbers.h" // https://gist.github.com/911872
struct node {
int key;
struct node *l;
struct node *r;
};
@radiofreejohn
radiofreejohn / makepairs.c
Created April 26, 2011 04:18
a routine I am working on to process sets of numbers
#include <stdlib.h>
#include <stdio.h>
#include "numbers.h" // https://gist.github.com/911872
struct Pair
{
int left;
int right;
};
struct Pairs
@radiofreejohn
radiofreejohn / mergesort.c
Created April 15, 2011 01:13
Simple mergesort from Sedgewick's Algorithms in C++
#include <stdio.h>
#include "numbers.h" // https://gist.github.com/911872
int main()
{
struct numbers a;
struct numbers b;
/*
I feel like a tool, sort of. I spent more time than I should admit using
generateRandoms here, forgetting that mergesort can only merge two arrays
@radiofreejohn
radiofreejohn / indirectHeapSort.c
Created April 13, 2011 23:42
a very janky indirect heap sort adapted from the C++ version in Sedgewick's Algorithms in C++
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "numbers.h" //https://gist.github.com/911872
void insert(int,int);
int hremove(void);
int hEmpty(void);
void swapsies(int*, int, int); //anandkunal knows
int *indirectHeapSort(struct numbers*); //heapsort conflicts with stdlib
@radiofreejohn
radiofreejohn / insertion-sort.c
Created April 11, 2011 23:53
insertion sort for my numbers structure
#include <stdio.h>
#include "numbers.h"
void insertionSort(struct numbers*);
int main()
{
struct numbers myNumbers = generateRandoms(1,10);
int i;
for (i = 0; i < myNumbers.size; i++)
@radiofreejohn
radiofreejohn / selection-sort.c
Created April 11, 2011 23:42
selection sort for my numbers structures
#include <stdio.h>
#include "numbers.h" // https://gist.github.com/911872
void selectionSort(struct numbers*);
void numberSwap(struct numbers*, int, int );
int main()
{
struct numbers myNumbers = generateRandoms(2,200);
int i;
@radiofreejohn
radiofreejohn / heap.c
Created April 9, 2011 23:42
heapSort with priority queue and test program
/*
heapSort example using priority queue from Sedgewick's Algorithms in C++
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "numbers.h" // https://gist.github.com/911872
void insert(int);
int hremove(void);
@radiofreejohn
radiofreejohn / numbers.c
Created April 9, 2011 23:02
structure and functions to generate ranges of integers
#include <math.h>
#include <stdlib.h>
#include <time.h>
struct numbers {
unsigned int size;
int *values;
};
struct Set {
const unsigned int size;
const int *values;
@radiofreejohn
radiofreejohn / randword.c
Created April 4, 2011 02:52
open a dictionary file and return a random word
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
/*
I wrote this as a sort of challenge, I wanted to pass random words into the K&R exercise
that generates a hash table of key value pairs to see how quickly the hashes stack up on
one another. I could have easily piped random words to the input, but that's not painful
at all...
*/
@radiofreejohn
radiofreejohn / range.c
Created March 23, 2011 04:27
generate a range of integer values range(start,end) - may be neg to pos and vice versa
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int *range(int, int);
int *range(int start, int end)
{
int size = (int) fabs(end-start)+1;
int *values = malloc(size * sizeof(int));