Characters in C have numeric values that happen to be in order, so you just treat your characters like integers. The C standard library includes a 'qsort' function. Use that ( man qsort on a linux-like system).
You might have to convert upper-case letters to lowercase to simplify things, but that's trivial. If you want to understand the quicksort algorithm (that's the one you should learn, because you'll actually use it), see Wikipedia.
Characters in C have numeric values that happen to be in order, so you just treat your characters like integers. The C standard library includes a 'qsort' function. Use that (man qsort on a linux-like system).
You might have to convert upper-case letters to lowercase to simplify things, but that's trivial. If you want to understand the quicksort algorithm (that's the one you should learn, because you'll actually use it), see Wikipedia.
Thanks for your comment Ben! – Nano Taboada Sep 23 '08 at 18:29.
If the result is intended for humans, it is better to use strcoll. It is slower then strcmp or strcasecmp but it accounts for non-english characters. If you are going to use it don't forget to set your locale for LC_COLLATE, i.e.
Setlocale(LC_COLLATE, "").
Use the qsort method: #include int char_compare (const void * a, const void * b) { return *(const char *)a - *(const char *)b; } int main(){ const char char_array = { 'c', 'a', 'b' }; qsort (char_array, 3, sizeof(char), char_compare); return 0; }.
That sorts an array of strings, he asked to sort an array of characters. – davr Sep 23 '08 at 18:11 oops yes. Thanks for noticing that.
– Rasmus Faber Sep 23 '08 at 18:36.
1 Buddy I already know how to use the Google, but I definitely preffer to rely on the expertise and reliability of the stackoverflow community. – Nano Taboada Sep 23 '08 at 18:26.
If the latter, then use C's qsort. If you want an algorith, go for Insertion sort or Selection sort, as they're very simple to understand.
Just try Bubble Sort that's the easiest sorting algorithm.
Not as slow as Bogosort – Rodrigo Queiro Sep 23 '08 at 18:16 Never claim an algorithm is the "slowest" for a particular task. One can always write a slower one. :) – Herms Sep 23 '08 at 18:20 Heh indeed, I'll remove the 'slowest'.
;) – unexist Sep 23 '08 at 19:29 1 IMHO, insertion sort is easier then bubble sort. – quinmars Sep 23 '08 at 12:54.
Do a bubble sort. This is java and int rather than char, but you can easily adapt it... int bubble(int a) { for (int I = a. Length; --i>=0; ) { for (int j = 0; j aj+1) { int T = aj; aj = aj+1; aj+1 = T; } } } return(a); }.
– Ben Sep 23 '08 at 18:05 Thanks but I can't use Java, I should implement the solution in plain C. – Nano Taboada Sep 23 '08 at 18:30.
Sounds like a homework assignment to me. Try reading wikipedia ...
Sounds like offensive to me. Try being more educated. – Nano Taboada Sep 23 '08 at 18:31.
This is pretty simple and asymptotically fastest (N is size of array): const unsigned char inN; unsigned char outN, *p=out; size_t cntN={0}, i, j; for (i=0; i.
Be the simplest way to alpha would (without quotes):. Be the simplest way to alpha sort an array of chars in c would (without quotes):.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.