Hal2k1 Posted October 17, 2004 Share Posted October 17, 2004 I need one algorithym to find a n bigger element inside a vector, without ordering it. Give n=5 find the 5 bigger element in the vector. Cant order the vector or use a seconde vector Link to comment Share on other sites More sharing options...
0 Hal2k1 Posted October 17, 2004 Author Share Posted October 17, 2004 cant touch the vector or use the qsort function... Link to comment Share on other sites More sharing options...
0 Mouton Posted October 18, 2004 Share Posted October 18, 2004 create a vector of size n (int *result = new int[n];). fill it with zeros. create an int to keep a reference to the smaller number saved in this vector (int min=0). this will tell u at what position is the smaller number, and thus where you should insert your next value. loop on your initial vector, filling your result vector with the numbers u find that are > result[min]. after each insert, find the smaller number in result and save it's position in min. though it would be easier to just make a copy of your vector and sort the copy... Link to comment Share on other sites More sharing options...
Question
Hal2k1
I need one algorithym to find a n bigger element inside a vector, without ordering it.
Give n=5 find the 5 bigger element in the vector. Cant order the vector or use a seconde vector
Link to comment
Share on other sites
2 answers to this question
Recommended Posts