954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

sort array

If i have 2 array contains data

1 50
2 30
3 40
4 70


if I want to sort in descending order which take nombor and data together...

4 70
1 50
3 40
2 30

How???

nurulshidanoni
Posting Whiz in Training
219 posts since Nov 2007
Reputation Points: 9
Solved Threads: 0
 

When you exchange one array during the sort you have to make similar exchanges in the second array. That's one reason that many (most?) programmers put suich things in an array of structures -- to make sorting a lot simpler.

struct data
{
    int a;
    int b;
};

Now instead of sorting two arrays you only have to sort one array of structures.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

If I put like this???

struct exam
{
string examid;
vector <int> total;
};
nurulshidanoni
Posting Whiz in Training
219 posts since Nov 2007
Reputation Points: 9
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You