Created
April 10, 2013 06:22
-
-
Save kvanbere/5352234 to your computer and use it in GitHub Desktop.
Aggressively Golfed C-99 Quicksort
This file contains 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> | |
#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