473,385 Members | 1,901 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Problem with inbuilt sort() function in c++

13
Explaining doubt with example ::

I have a vector of pair say vv having values vv[0]=(9,1) vv[1]=(13,2) vv[2]=(9,3) vv[3]=(6,4) vv[4]=(9,5)

and an array 'aa' having values {5,10,1,4,3}

now using sort func., i want to sort my vector of pair such that if vv[i].first==vv[j].first then the one having larger value of aa[vv[i].second] and aa[vv[j].second] should come first otherwise normal sort.

so in this case for vector sorts to (6,4) (9,1) (9,5) (9,3) (13,2) because aa[1]>aa[5]>aa[3]

How should i modify inbuilt sort() to implement such behaviour.
Jun 2 '10 #1
1 2058
Banfa
9,065 Expert Mod 8TB
Since vector does not have a sort method i assume by built in sort you are referring to std::sort from algorithm.

There is no need to modify the sort itself, just use the second overload that accepts a comparison function or functor as the third parameter and write a function or functor to implement your desired comparison using both vectors.
Jun 2 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Shaunak Kashyap | last post by:
Does anyone know what sorting algorithm(s) -- quicksort, mergesort, radix sort, etc. -- does PHP use internally in its sort function?
1
by: Alexandru | last post by:
Hello fellows. i have a problem with unlink function. if i'm trying to use uplink like this: unlink("../home/meks_party.jpg"); i got the message: Warning: unlink(../home/meks_party.jpg): No...
2
by: Ken R. | last post by:
Hello all, I am relatively new to python but I am having an issue with custom sort functions.. I am trying to sort a list of lists or tuples with arbitrary ascending or descending sorts. For...
2
by: Fawke101 | last post by:
Hi there, I have a JS/ASP application that sorts a SQL populated table. This works great, and sorts the data fine, apart from my currency columns. It wants to read the data as text as far as i...
2
by: Rachel Forder | last post by:
Hi All, I have a problem related to the sort function provided by STL. class A{ A(string, string, int); string itemA; string itemB; int itemC; };
7
by: Pat | last post by:
class data { public: double time; // other functions.... } I want to put a lot of "data" classes into a container, and the data order should be sorted according to "time" variable. One of...
20
by: Xah Lee | last post by:
Sort a List Xah Lee, 200510 In this page, we show how to sort a list in Python & Perl and also discuss some math of sort. To sort a list in Python, use the “sort” method. For example: ...
0
by: =?iso-8859-1?Q?=22Orlando_D=F6hring=22?= | last post by:
Dear community, I want to use the sort function to sort a (nested) list. General information can be found below. http://www.python.org/doc/2.4.2/lib/typesseq-mutable.html...
1
by: john20 | last post by:
Hi All, I am having a problem with accesing function in the page. i have a page say user.aspx in the page load method i am calling function to validate the user. it works fine when single...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.