|
| |||||||||
| Tags: algorithm, cpp, functions, header files, library, sort |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| How the sort() can be used in CPP programming
Hi, I am the student of the BSC-IT. I could had the well knowledge of the C++ programming language. I had also created the one project in the C++ programming language. But I could not know much more about the built-in functions of C++ programming language. So, I would like to know about the sort() function of the C++ language. I also would like to know about how can I use the sort() function in the C++ programming language. Thus, Can anyone has the proper answer on the sort() function in the C++ language. Reply Me!!! |
|
#2
| ||||
| ||||
| The sort()
Hello, The sort() function can be used in the C++ language to Sorts the elements in the given specified range [fst,lst) into an ascending order. The following can be the general syntax of the sort(0 function in the C++ language as : Code: template <class RndmAcesItrtr> void sort ( RndmAcesItrtr fst, RndmAcesItrtr lst ); |
|
#3
| |||
| |||
| How the sort() can be used in CPP
The following can be the parameters of the sort() function in the C++ programming language : 1. comp : This parameter can be used in the sort() function of the C++ language for an object of the Comparison function that can taking two values of the same type than those can be contained in the given specified range. 2. fst, lst : These parameters can be used in the sort() function of the C++ language for Random-Access iterators to the final and starting positions of the sequence that can be sorted. The range used can be [fst,lst). |
|
#4
| ||||
| ||||
| Re: How the sort() can be used in CPP programming
The following program could states you that how you can use the sort() function in the C++ language programming while using the sort() function in the programming as shown below : Code: #include <iostream>
#include <algorithm>
#include <cassert>
using namespace std;
int main()
{
int b[1000];
int j;
for (j = 0; j < 1000; ++j)
b[j] = 1000 - j - 1;
sort(&b[0], &b[1000]);
for (j = 0; j < 1000; ++j)
assert (b[j] == j);
return 0;
} |
|
#5
| ||||
| ||||
| sort() function can be used in CPP programming Program : Code: #include <iostream>
#include <algorchm>
#include <vector>
using namespace std;
bool mfnctn (int i,int j)
{
return (i<j);
}
struct myclass
{
bool operator() (int i,int j)
{
return (i<j);
}
}
myobject;
int main ()
{
int mint[] = {32,71,12,45,26,80,53,33};
vector<int> mvctr (mint, mint+8);
vector<int>::cerator c;
sort (mvctr.begin(), mvctr.begin()+4);
sort (mvctr.begin()+4, mvctr.end(), mfnctn);
sort (mvctr.begin(), mvctr.end(), myobject);
cout << "mvctr contains:";
for (c=mvctr.begin(); c!=mvctr.end(); ++c)
cout << " " << *c;
cout << endl;
return 0;
} Code: mvctr contains: 12 26 32 33 45 53 71 80 |
|
#6
| ||||
| ||||
| Re: How the sort() can be used in CPP programming
The sort() function algorithm can be used to sort the elements in the given specified range [strt,nd) in the ascending order. Suppose that there can be the two elements with the equal value, there can be no guarantee to in what order these two elements could be in. If there can be the strict weak ordering function of an object cp can be given, then it could be used to compare two objects in-spite of the < operator. |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "How the sort() can be used in CPP programming" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to sort the name in Excel | Sanju Baba | Windows Software | 1 | 06-01-2012 10:53 PM |
| What is the difference between binary tree sort and heap sort in data structure | sRIPRIYA | Software Development | 3 | 04-01-2011 01:25 AM |
| Socket programming: Is any new Programming Language? | Kushan | Software Development | 3 | 14-11-2009 11:13 AM |
| How to use Bubble sort in C# to sort parallel arraylists | Ground 0 | Software Development | 3 | 03-08-2009 01:12 PM |
| JetBrains Introduces a New Programming Paradigm With its Meta Programming System | JoeFrat | Software Development | 3 | 13-12-2008 01:49 PM |