| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
I'm having trouble trying to sort two arrays on C++, using bubble sort. I have to promt for user ID numbers, then prompt for salary then sort it.
|
|
#2
|
|||
|
|||
|
Hello,
Think of your question like this, if I had 2 complex numbers A and B, how could I tell which one is larger? The answer is you can't because there is no definitive answer, the reason being the equality operators only work on 1 dimensional values. So in fact your problem is not one of sorting 2 dimensional arrays. Now back to your problem, I think what is need from you is to sort the array initially according to ID, then where the ID's are similar in the array to sort according salary. One interesting property about the bubble sort is that it is a nonvolatile sorting algorithm, meaning the relative position of elements (similar elements are maintained during the sorting process). So in theory if you were to sort the whole array according to the salary values, then do a whole sort again according to the ID values you will have maintained the relative position of salaries amongst similar IDs Arash Partow __________________________________________________ Be one who knows what they don't know, Instead of being one who knows not what they don't know, Thinking they know everything about all things. http://www.partow.net |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > How do I sort two dimentional arrays using bubble sort? C++ |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|