We’re rewarding the question askers & reputations are being recalculated! Read more.
4 added 10 characters in body
source | link

C

Simply by using recursion instead of loops. This particular version only works on characters between '0' and 'z', but that's just to keep the stack from overflowing too often. Supporting all of ASCII.

#include <stdio.h>

void walk(char *s, char m){
    if (*s == '\0') return;
    if (*s == m) putchar(m);
    walk(s+1,m);
}

void sort(char *s, char m){
  walk(s,m);
  if (m<127) sort(s,m+1);
}

int main(int argc, char**argv){
  if (argc > 1) {
    printf("%s: ",argv[1]);
    sort(argv[1],1);
    printf("\n");
  }
}

Sample run:

$ ./a.out  thingamabob
thingamabob: aabbghimnot
$ ./a.out  supercalifragilisticexpalodoucious
supercalifragilisticexpalodoucious: aaacccdeefgiiiiilllooopprrssstuuux
$ ./a.out  "The quick red fox jumped over the lazy brown dog"
The quick red fox jumped over the lazy brown dog:          Tabcdddeeeeefghhijklmnoooopqrrrtuuvwxyz

Too easy, really.

Simply by using recursion instead of loops. This particular version only works on characters between '0' and 'z', but that's just to keep the stack from overflowing too often. Supporting all of ASCII.

#include <stdio.h>

void walk(char *s, char m){
    if (*s == '\0') return;
    if (*s == m) putchar(m);
    walk(s+1,m);
}

void sort(char *s, char m){
  walk(s,m);
  if (m<127) sort(s,m+1);
}

int main(int argc, char**argv){
  if (argc > 1) {
    printf("%s: ",argv[1]);
    sort(argv[1],1);
    printf("\n");
  }
}

Sample run:

$ ./a.out  thingamabob
thingamabob: aabbghimnot
$ ./a.out  supercalifragilisticexpalodoucious
supercalifragilisticexpalodoucious: aaacccdeefgiiiiilllooopprrssstuuux
$ ./a.out  "The quick red fox jumped over the lazy brown dog"
The quick red fox jumped over the lazy brown dog:          Tabcdddeeeeefghhijklmnoooopqrrrtuuvwxyz

Too easy, really.

C

Simply by using recursion instead of loops. This particular version only works on characters between '0' and 'z', but that's just to keep the stack from overflowing too often. Supporting all of ASCII.

#include <stdio.h>

void walk(char *s, char m){
    if (*s == '\0') return;
    if (*s == m) putchar(m);
    walk(s+1,m);
}

void sort(char *s, char m){
  walk(s,m);
  if (m<127) sort(s,m+1);
}

int main(int argc, char**argv){
  if (argc > 1) {
    printf("%s: ",argv[1]);
    sort(argv[1],1);
    printf("\n");
  }
}

Sample run:

$ ./a.out  thingamabob
thingamabob: aabbghimnot
$ ./a.out  supercalifragilisticexpalodoucious
supercalifragilisticexpalodoucious: aaacccdeefgiiiiilllooopprrssstuuux
$ ./a.out  "The quick red fox jumped over the lazy brown dog"
The quick red fox jumped over the lazy brown dog:          Tabcdddeeeeefghhijklmnoooopqrrrtuuvwxyz

Too easy, really.

3 added 157 characters in body; added 171 characters in body
source | link

Simply by using recursion instead of loops. This particular version only works on characters between '0' and 'z', but that's just to keep the stack from overflowing too oftenThis particular version only works on characters between '0' and 'z', but that's just to keep the stack from overflowing too often. Supporting all of ASCII.

#include <stdio.h>

void walk(char *s, char m){
    if (*s == '\0') return;
    if (*s == m) putchar(m);
    walk(s+1,m);
}

void sort(char *s, char m){
  walk(s,m);
  if (m<'z'm<127) sort(s,m+1);
}

int main(int argc, char**argv){
  if (argc > 1) {
    printf("%s: ",argv[1]);
    sort(argv[1],'0'1);
    printf("\n");
  }
}

Sample run:

$ ./a.out  thingamabob
thingamabob: aabbghimnot
$ ./a.out  supercalifragilisticexpalodoucious
supercalifragilisticexpalodoucious: aaacccdeefgiiiiilllooopprrssstuuux
$ ./a.out  "The quick red fox jumped over the lazy brown dog"
The quick red fox jumped over the lazy brown dog:          Tabcdddeeeeefghhijklmnoooopqrrrtuuvwxyz

Too easy, really.

Simply by using recursion instead of loops. This particular version only works on characters between '0' and 'z', but that's just to keep the stack from overflowing too often.

#include <stdio.h>

void walk(char *s, char m){
    if (*s == '\0') return;
    if (*s == m) putchar(m);
    walk(s+1,m);
}

void sort(char *s, char m){
  walk(s,m);
  if (m<'z') sort(s,m+1);
}

int main(int argc, char**argv){
  if (argc > 1) {
    printf("%s: ",argv[1]);
    sort(argv[1],'0');
    printf("\n");
  }
}

Sample run:

$ ./a.out  thingamabob
thingamabob: aabbghimnot

Too easy, really.

Simply by using recursion instead of loops. This particular version only works on characters between '0' and 'z', but that's just to keep the stack from overflowing too often. Supporting all of ASCII.

#include <stdio.h>

void walk(char *s, char m){
    if (*s == '\0') return;
    if (*s == m) putchar(m);
    walk(s+1,m);
}

void sort(char *s, char m){
  walk(s,m);
  if (m<127) sort(s,m+1);
}

int main(int argc, char**argv){
  if (argc > 1) {
    printf("%s: ",argv[1]);
    sort(argv[1],1);
    printf("\n");
  }
}

Sample run:

$ ./a.out  thingamabob
thingamabob: aabbghimnot
$ ./a.out  supercalifragilisticexpalodoucious
supercalifragilisticexpalodoucious: aaacccdeefgiiiiilllooopprrssstuuux
$ ./a.out  "The quick red fox jumped over the lazy brown dog"
The quick red fox jumped over the lazy brown dog:          Tabcdddeeeeefghhijklmnoooopqrrrtuuvwxyz

Too easy, really.

2 deleted 7 characters in body
source | link

Simply by using recursion instead of loops. This particular version only works on characters between '0' and 'z', but that's just to keep the stack from overflowing too often.

#include <stdio.h>

void walk(char *s, char m){
    if (*s == '\0') return;
    if (*s == m) putchar(m);
    return walk(s+1,m);
}

void sort(char *s, char m){
  walk(s,m);
  if (m<'z') sort(s,m+1);
}

int main(int argc, char**argv){
  if (argc > 1) {
    printf("%s: ",argv[1]);
    sort(argv[1],'0');
    printf("\n");
  }
}

Sample run:

$ ./a.out  thingamabob
thingamabob: aabbghimnot

Too easy, really.

Simply by using recursion instead of loops. This particular version only works on characters between '0' and 'z', but that's just to keep the stack from overflowing too often.

#include <stdio.h>

void walk(char *s, char m){
    if (*s == '\0') return;
    if (*s == m) putchar(m);
    return walk(s+1,m);
}

void sort(char *s, char m){
  walk(s,m);
  if (m<'z') sort(s,m+1);
}

int main(int argc, char**argv){
  if (argc > 1) {
    printf("%s: ",argv[1]);
    sort(argv[1],'0');
    printf("\n");
  }
}

Sample run:

$ ./a.out  thingamabob
thingamabob: aabbghimnot

Too easy, really.

Simply by using recursion instead of loops. This particular version only works on characters between '0' and 'z', but that's just to keep the stack from overflowing too often.

#include <stdio.h>

void walk(char *s, char m){
    if (*s == '\0') return;
    if (*s == m) putchar(m);
    walk(s+1,m);
}

void sort(char *s, char m){
  walk(s,m);
  if (m<'z') sort(s,m+1);
}

int main(int argc, char**argv){
  if (argc > 1) {
    printf("%s: ",argv[1]);
    sort(argv[1],'0');
    printf("\n");
  }
}

Sample run:

$ ./a.out  thingamabob
thingamabob: aabbghimnot

Too easy, really.

1
source | link