Skip to content

Instantly share code, notes, and snippets.

@kvanbere
Created April 10, 2013 06:22
Show Gist options
  • Save kvanbere/5352234 to your computer and use it in GitHub Desktop.
Save kvanbere/5352234 to your computer and use it in GitHub Desktop.
Aggressively Golfed C-99 Quicksort
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static char str_[] = "C programming is fun!", *buf_, tmp_;
void sort(char *src_, char *dst_, int n_)
{
if (!src_[n_] || (n_ <= 1)) return;
if (dst_[n_] >= (tmp_ = dst_[n_ - 1])) return;
dst_[n_ - 1] = dst_[n_];
dst_[n_] = tmp_;
sort(src_, dst_, n_ - 1);
}
int main(int argc, char *argv[])
{
memcpy(buf_ = calloc(sizeof(str_), 1), str_, sizeof(str_));
for (int i = 0; i < sizeof(str_); ++i)
sort(str_, buf_, i);
for (int j = 0; j < sizeof(str_); ++j)
if (buf_[j] != ' ') putchar(buf_[j]);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment