# Thread: Sort values in an array without using sort functions (Urgent)

1. ## Sort values in an array without using sort functions (Urgent)

Hello,

I need help with re-ordering the values in ascending order in the array (Unordered). However, I cannot use swap or sort function (i.e. Bubblesort).

How can I do that?

2. Originally Posted by fedya
I need help with re-ordering the values in ascending order in the array (Unordered). However, I cannot use swap or sort function (i.e. Bubblesort).
You might want to elaborate. Why is it that you "cannot use swap or sort function (i.e. Bubblesort)"? Taking that restriction literally, the simple solution is to use qsort(), since it is neither a swap function nor is it likely to be an implementation of bubblesort.

3. Originally Posted by fedya
Hello,

I need help with re-ordering the values in ascending order in the array (Unordered). However, I cannot use swap or sort function (i.e. Bubblesort).

How can I do that?
I think you've asked the same question few days ago here and Adak has beautifully explained it.

4. Originally Posted by fedya
Hello,

I need help with re-ordering the values in ascending order in the array (Unordered). However, I cannot use swap or sort function (i.e. Bubblesort).

How can I do that?
You can't. As I told you last time it's a logical contradiction to have some code that sorts something (which itself is therefore a sorting algorithm) and to also not use a sorting algorithm.
It's like asking us how you can run a running race without moving your legs.

You just don't seem to be learning what's wrong with your question.

5. Originally Posted by BEN10
I think you've asked the same question few days ago here and Adak has beautifully explained it.
Thanks Ben10.

This is another example for you, fedya.

Code:
```/* IndxSort.c by Adak. A small example of sorting through an index
status: ok
*/

#include <stdio.h>

#define NumItems 4
#define StringLen 30

int main() {

int i, j, temp;

int Index[NumItems];
//make 2 arrays, (which work in parallel). One for strings, and one for the int
int Int[NumItems] = { 7, 2, 11, 6 };

//and a few lines from The Rhyme of the Ancient Mariner:
char Strings[NumItems][StringLen] = {
{  "Water, water, everywhere" },
{  "And all the boards did shrink" },
{  "Water, water, everywhere" },
{  "Nor any drop to drink" }
};

//initialize the index array
for(i = 0; i < NumItems; i++)
Index[i] = i;

//now a simple sort, using the initialized index array and the Int array

for(i = 0; i < NumItems - 1; i++)  {
for(j = i + 1; j < NumItems; j++)  {
if(Int[Index[i]] > Int[Index[j]] ) {
temp = Index[i];
Index[i] = Index[j];
Index[j] = temp;
}
}
}

//Now to see the sorted data, using the Index array
printf("\n\n\n Int and String data, sorted by the index Int[]:\n\n");
for(i = 0; i < NumItems; i++)
printf("Int: %2d  String: %s \n", Int[Index[i]], Strings[Index[i]]);

printf("\n\n\n Original Int and String data:\n\n");
//to see the unsorted data
for(i = 0; i < NumItems; i++)
printf("Int: %2d  String: %s \n", Int[i], Strings[i]);