Skip to content

Instantly share code, notes, and snippets.

View radiofreejohn's full-sized avatar
🤓

John radiofreejohn

🤓
  • Goldsky
  • Raleigh, NC
View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / filecomp.c
Created May 30, 2011 22:29
K&R exercise 7-6 compare two files
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXLINE 1000
int main(int argc, char *argv[])
{
FILE *fileA, *fileB;
char filenameA[257];
char filenameB[257];
char *prog = argv[0];
@radiofreejohn
radiofreejohn / bruteforce.c
Created June 19, 2011 22:03
brute force string search
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int brutesearch(char *p, char *a)
{
int i, j, M = strlen(p), N = strlen(a);
for (i = 0, j = 0; j < M && i < N; i++, j++)
{
if (a[i] != p[j])
@radiofreejohn
radiofreejohn / itob.c
Created July 23, 2011 06:04
integer to binary string
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
char *itob(char *buffer, int x)
{
unsigned int z = INT_MAX + 1U;
char *buf = buffer;
do
@radiofreejohn
radiofreejohn / nv3h_read_gz.c
Created January 11, 2012 02:12
IDL dlm to read formatted ASCII files
/*
* gcc nv3h_read_gz.c -shared -Bsymbolic -I/zshare/rsi/idl_6.3/external/include -L/zshare/rsi/idl_6.3/bin/bin.linux.x86_64 -lidl -o nv3h_read_gz.so -fPIC -lz -ldl
*
* requires zlib 1.2.5 for gzbuffer -- will check for right version
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <zlib.h>