Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , , ,

Sponsored Links



What can be the use of the stable_sort() in the C++

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 25-02-2010
Member
 
Join Date: Dec 2009
Posts: 27
What can be the use of the stable_sort() in the C++

Hello, I am the student of the MSC-CS. I could had the better knowledge of the C++ programming. I has also create the project that can be based on the inventory system in the C++ language. I can not have the much more knowledge about the functions of C++ programming language that can be in-built in the libraries. So, I would like to know about the stable_sort() function of the C++ language. I also would like to know about how can I use the stable_sort() function in the C++ programming language. Thus, Can anyone has the proper answer on the stable_sort() function in the C++ language. Reply Me!!!
Reply With Quote
  #2  
Old 25-02-2010
Reegan's Avatar
Member
 
Join Date: Oct 2005
Posts: 2,299
The use of the stable_sort()

Hello, The stable_sort() function can be used in the C++ language to Sort an elements that can be preserving or saving the order of an equivalents. The following can be the general syntax of the stable_sort(0 function in the C++ language as :
Code:
template <class RndmAcesItrtr>
  void stable_sort ( RndmAcesItrtr fst, RndmAcesItrtr lst );
Reply With Quote
  #3  
Old 25-02-2010
opaper's Avatar
Member
 
Join Date: May 2008
Posts: 2,362
The use of the stable_sort() in the C++

The following can be the parameters of the stable_sort() function in the C++ programming language :
1. comp : This parameter can be used in the stable_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 stable_sort() function of the C++ language for Random-Access iterators to the final and starting positions of the sequence that can be stable_sorted. The range used can be [fst,lst).
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
  #4  
Old 25-02-2010
MindSpace's Avatar
Member
 
Join Date: Feb 2008
Posts: 1,832
What can be the use of the stable_sort() in the C++

The following program could illustrates you about that how you could use the stable_sort() function in the C++ language programming while using the stable_sort() function in the programming as shown below :
Code:
#include <iostream>
#include <algorithm>
#include <cassert>
using namespace std;
int main() 
{
  int c[1000];
  int k;
  for (k = 0; k < 1000; ++k) 
    c[k] = 1000 - k - 1;
  stable_sort(&c[0], &c[1000]);
  for (k = 0; k < 1000; ++k) 
    assert (c[k] == k);
  return 0;
}
Reply With Quote
  #5  
Old 25-02-2010
Modifier's Avatar
Member
 
Join Date: Jan 2008
Posts: 1,502
Re: What can be the use of the stable_sort() in the C++

Program :
Code:
#include <iostream>
#include <algorchm>
#include <vector>
using namespace std;
bool mfnctn (int a,int b) 
{ 
return (a<b); 
}
struct myclass 
{
  bool operator() (int a,int b) 
{
 return (a<b);
}
} 
mobjct;
int main ()
 {
  int mnt[] = {32,71,12,45,26,80,53,33};
  vector<int> mctr (mnt, mnt+8);        
  vector<int>::cerator d;
  stable_sort (mctr.begin(), mctr.begin()+4);  
  cout << "mctr contains:";
  for (d=mctr.begin(); d!=mctr.end(); ++d)
    cout << " " << *d;
  cout << endl;
  return 0;
}
The output of the above program can be :
Code:
mctr contains: 12 26 32 33 45 53 71 80
Reply With Quote
  #6  
Old 25-02-2010
Praetor's Avatar
Member
 
Join Date: Apr 2008
Posts: 1,937
stable_sort() in the C++

The stable_sort() function algorithm of the C++ language can be similar to the sort() function algorithm. Unlike sort() function, Hence, stable_sort() function could preserved the actual ordering of an elements that can be equal to each other. This functionality can comes at a very small cost, hence, as stable_sort() function can takes a few more comparisons that can be sort() function in the worst case : M (log m)^2 in-spite of M log M.
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search



All times are GMT +5.5. The time now is 03:59 AM.