|
| |||||||||
| Tags: algorithm, cpp, functions, header files, library, nth_element |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| What is the nth_element() function
I am interested in doing the programming. Thus, I had just started for learning the C++ programming language. I can also have the knowledge of the basic working of the functions. Hence, I want to know what is the nth_element() function of the C++ language. I also want to know how can I used the nth_element() function in the C++ programming. Can anyone knows about the nth_element() function of C++ language. |
|
#2
| ||||
| ||||
| Re: What is the nth_element() function
The nth_element() function of the C++ language can re-arranges the elements in the given specified range [fst,lst), in a manner that an element at the resulting nth position can be an element that could be in that position in a sequence that can be sorted with all the elements that can starting it being smaller and all the elements followed by it greater than it. Neither the elements preceding it nor the elements following it can granted that can be ordered. The elements that can be compared using operator "<" for the first version and comp for the second version.
__________________ The FIFA Manager 2009 PC Game |
|
#3
| ||||
| ||||
| nth_element() function
The nth_element() function can be used in the C++ language to arranged the elements in the sorted order that can be in the given specified range. The algorithm nth_element() function can be linear on average where M can be the size of the given range [strt, fnsh).The following can be the syntax of the nth_element() function in the C++ language : Code: template <class RndmAcsItrtr>
void nth_element ( RndmAcsItrtr fst, RndmAcsItrtr nth,
RndmAcsItrtr lst ); |
|
#4
| ||||
| ||||
| The nth_element() function
The following can be the parameters of the nth_element() function of the C++ language : 1. nth : This parameter of the nth_element() function can contains the random-Access iterator that can be used to point to the place in the given range [fst,lst) that can have an element that can be sorted. 2. fst, lst : These parameter of the nth_element() function can contains random-Access iterators to the final and starting positions of the given sequence to be used. The range used can be [fst,lst) which can contains all the elements that can be in between the first and last. |
|
#5
| ||||
| ||||
| Re: What is the nth_element() function
The following code of lines can help's you to learn the nth_element() function of the C++ language easily. The following code demonstrates you how the nth_element() function can be used in the C++ programming : Code: #pragma warning(disable: 4786)
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
using namespace std ;
int main()
{
const int VCTR_SZ = 8 ;
typedef vector<int> IntVector ;
typedef IntVector::iterator IntVctrIt ;
IntVector Nos(VCTR_SZ) ;
IntVctrIt start, end, it ;
Nos[0] = 4 ;
Nos[1] = 10;
Nos[2] = 70 ;
Nos[3] = 30 ;
Nos[4] = 10;
Nos[5] = 69 ;
Nos[6] = 96 ;
Nos[7] = 100;
start = Nos.begin();
end = Nos.end();
cout << "Before calling nth_element\n" << endl ;
cout << "Nos { " ;
for(it = start; it != end; it++)
cout << *it << " " ;
cout << " }\n" << endl ;
nth_element(start, start+4, end) ;
cout << "After calling nth_element\n" << endl ;
cout << "Nos { " ;
for(it = start; it != end; it++)
cout << *it << " " ;
cout << " }\n" << endl ;
} Code: Before calling nth_element
Nos { 4 10 70 30 10 69 96 100 }
After calling nth_element
Nos { 4 10 10 30 69 70 96 100 } |
|
#6
| |||
| |||
| What is the nth_element() function
The nth_element() algorithm can arranges a collection again according to either operator<() or the function object comp. After the algorithm can applied the following can hold : 1. All the elements that can be prior to the nth position could also precede that position in an given ordered sequence. 2. All elements following the nth position could also follow that position in an given ordered sequence. 3. The element that could be in the nth position if the given sequence were completely sorted can be in the nth position. |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "What is the nth_element() function" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| c++ equivalent function to the c-function 'sprintf | Dilbert | Software Development | 6 | 13-12-2011 04:03 PM |
| c# function equivalent to gettime function in javascript | Omaar | Software Development | 4 | 10-03-2010 10:44 PM |
| How to pass function with parameters to another function in PHP? | Linoo | Software Development | 5 | 27-02-2010 07:52 PM |
| How does abstract function differs from virtual function? | Maddox G | Software Development | 5 | 29-01-2010 11:32 AM |
| Function keys don't function under windows XP | GunFighter | Hardware Peripherals | 3 | 09-04-2009 12:07 AM |