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?
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 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.Originally Posted by fedya
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
I think you've asked the same question few days ago here and Adak has beautifully explained it.
HOPE YOU UNDERSTAND.......
By associating with wise people you will become wise yourself
It's fine to celebrate success but it is more important to heed the lessons of failure
We've got to put a lot of money into changing behavior
PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
IDE- Microsoft Visual Studio 2008 Express Edition
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.
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"
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]); printf("\n\n\t\t\t press enter when ready"); i = getchar(); return 0; }