#1
 Adolfa Member Join Date: Dec 2009 Posts: 27
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
 opaper Member Join Date: May 2008 Posts: 2,383
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
 MindSpace Member Join Date: Feb 2008 Posts: 1,848
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
 Modifier Member Join Date: Jan 2008 Posts: 1,515
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
 Praetor Member Join Date: Apr 2008 Posts: 1,948
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 = 4 ;
Nos = 10;
Nos = 70 ;
Nos = 30 ;
Nos = 10;
Nos = 69 ;
Nos = 96 ;
Nos = 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 ;
}```
The above code of lines can produce the following Output :
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
 Katty Member Join Date: May 2008 Posts: 2,008
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.

 Tags:

 Thread Tools Search this Thread Show Printable Version Email this Page Search this Thread: Advanced Search 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 08-04-2009 11:07 PM

All times are GMT +5.5. The time now is 06:38 PM.