473,802 Members | 2,017 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What is the name of sorting algorithm used in list (STL) class?

Dear All,

What is the name of sorting algorithm used in list (STL) class? and how it
work?
Thanks!!!

Best Regards,
Wahoo
~ Let us linux ~
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 22 '05 #1
5 1864

"Wahoo" <wa***@yahoo.co m> wrote in message news:40******@l ungfunggdn.org. ..
Dear All,

What is the name of sorting algorithm used in list (STL) class? and how it
work?


It is sort.
E.g.
#include <list>
#include <iostream>
using namespace std;

int main(){
list<int> l;
list<int>::cons t_iterator itr;
l.push_back(5);
l.push_back(4);
l.push_back(17) ;
l.push_back(3);
l.sort();
for (itr = l.begin(); itr != l.end(); ++itr)
cout << *itr; //print 34517
}

-Sharad
Jul 22 '05 #2

"Sharad Kala" <no************ *****@yahoo.com > schrieb im Newsbeitrag
news:2h******** ****@uni-berlin.de...

"Wahoo" <wa***@yahoo.co m> wrote in message

news:40******@l ungfunggdn.org. ..
Dear All,

What is the name of sorting algorithm used in list (STL) class? and how it work?


It is sort.


Er, I think the question was: What does list<T>.sort() do?
I'm not sure if the method is defined in std C++, but only the result
is. To see what your implementation does open the file "list" from
your include directory and search for list().
--
-Gernot
int main(int argc, char** argv) {printf
("%silto%c%cf%c gl%ssic%ccom%c" , "ma", 58, 'g', 64, "ba", 46, 10);}

_______________ _______________ __________
Looking for a good game? Do it yourself!
GLBasic - you can do
www.GLBasic.com
Jul 22 '05 #3
Wahoo wrote:
Dear All,

What is the name of sorting algorithm used in list (STL) class? and how it
work?
Thanks!!!

Best Regards,
Wahoo
~ Let us linux ~
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----


std::lists have a sort method, as demonstrated in another reply by Sharad.

In general you can sort any STL container with a random access iterator
using one of the algorithms listed below, declared in <algorithm>.

template<class RandomAccessIte rator>
void sort(RandomAcce ssIterator first, RandomAccessIte rator last);

template<class RandomAccessIte rator, class Compare>
void sort(RandomAcce ssIterator first, RandomAccessIte rator last,
Compare comp);

template<class RandomAccessIte rator>
void stable_sort(Ran domAccessIterat or first, RandomAccessIte rator last);

template<class RandomAccessIte rator, class Compare>
void stable_sort(Ran domAccessIterat or first, RandomAccessIte rator last,
Compare comp);

template<class RandomAccessIte rator>
void partial_sort(Ra ndomAccessItera tor first,
RandomAccessIte rator middle,
RandomAccessIte rator last);

template<class RandomAccessIte rator, class Compare>
void partial_sort(Ra ndomAccessItera tor first,
RandomAccessIte rator middle,
RandomAccessIte rator last,
Compare comp);

template<class InputIterator, class RandomAccessIte rator>
RandomAccessIte rator
partial_sort_co py(InputIterato r first, InputIterator last,
RandomAccessIte rator result_first,
RandomAccessIte rator result_last);

template<class InputIterator, class RandomAccessIte rator,
class Compare>
RandomAccessIte rator
partial_sort_co py(InputIterato r first, InputIterator last,
RandomAccessIte rator result_first,
RandomAccessIte rator result_last,
Compare comp);

As an example, consider the following:

#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>

using namespace std ;

int main()
{
vector<unsigned > v ;
unsigned i ;

for (i = 32; i > 0; i--)
v.push_back(i) ;

sort<vector<uns igned>::iterato r>(v.begin(), v.end()) ;

copy(v.begin(), v.end(), ostream_iterato r<unsigned>(cou t, " ")) ;
cout << endl ;

return 0 ;
}

Alan
Jul 22 '05 #4
Alan Johnson wrote:
Wahoo wrote:
Dear All,

What is the name of sorting algorithm used in list (STL) class?


sort<vector<uns igned>::iterato r>(v.begin(), v.end()) ;


Actually, and I realized this just after posting, the compiler should be
able to infer the template type from the parameters (is this allowed by
the standard?), so this line could be changed to:

sort(v.begin(), v.end()) ;
Alan
Jul 22 '05 #5
On 19 May 2004 13:27:24 +0800, "Wahoo" <wa***@yahoo.co m> wrote:
Dear All,

What is the name of sorting algorithm used in list (STL) class? and how it
work?


I think it's generally implemented as a mergesort, or some variant of
it. It is a divide and conquer algorithm, where to recursively sort
each half of the sequence and then merge the two sorted halves
together - it's a good algorithm for linked lists, since merge is
quite efficient for linked lists.

Tom
--
C++ FAQ: http://www.parashift.com/c++-faq-lite/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
Jul 22 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
2562
by: Hunter Hou | last post by:
Folks, I am just curious why standard library doesn't provide a "merge" operation without sorting, because sometimes I don't require sorting, just merge. I looked at list.merge() and merge() algorithm, both require sorted sequenece. Thanks, Hunter
11
5797
by: velthuijsen | last post by:
I tried taking a list and pass it through std::sort like the following: sort(Unsorted.begin(), Unsorted.end()); I got an error back stating that the list iterator doesn't have a binary substraction operator. Peeking in the algoritm header file it's clear why seeing that sort there calls _sort(_First, _Last, _Last-_First) which might be a tad challenging seeing that the different values stored in a list do not need to be stored...
2
6468
by: yee young han | last post by:
I need a fast data structure and algorithm like below condition. (1) this data structure contain only 10,000 data entry. (2) data structure's one entry is like below typedef struct _DataEntry_ { char szInput; char szOutput; int iSum;
1
5073
by: Prasad Karunakaran | last post by:
I am using the C# DirectoryEntry class to retrieve the Properties of an user object in the Active Directory. I need to get the First Name and Last Name as properties. I know it is not supported with the ADSI NT Provider and only supported in the LDAP Provider. So given an UserId (UID) how can I read the First Name and Last Name using LDAP Provider. If anybody can help me with a C# sample code it would of great help. Thanks in advance.
17
4345
by: Allerdyce.John | last post by:
Hi, I am trying to compare the amount of work between using STL algorithm VS a plain Java loop. Let's say the class Rect has 2 attributes: area, and areaPerCent. In Java, I just write a plain for loop with a list: public static void calculateAreaPerCent(List rectList, float containerArea) {
4
1924
by: _Raven | last post by:
Okay, I am playing with submitting forms with Ajax. I am trying to adapt this script to my forms: http://www.captain.at/howto-ajax-form-post-get.php I have included my code at the bottom of this post. Basically, this will work correctly if I remove all non-form related tags from the form =eg span, div, but I want to format the form all pretty like so??? Right now, it only collects 2 parts of the form fields =sites &
3
9869
by: Nelis Franken | last post by:
Good day. I'm having trouble telling STL to use a member function to sort items within the relevant class. The isLess() function needs to have access to the private members of the Foo class to determine if the one item is less than the other (it uses two vectors, one containing the actual data, and one that stores IDs that index into the data vector). The code below is pretty self-explanatory. I've looked into mem_fun, but I'm stuck....
6
1694
by: Yin Zhu | last post by:
Hello all, I haved used STL in writing some arithmetic programs for a while now. There are some very convenient to use, such as map(use it as a mapping array), set(use it as a dictionary for Insert, Delete, Exist query ..), vector(a varying length array, O(1) push under amortization) but STL didn't support other function , such as *)findKth in set, althought rb-tree can easily be augmented to support this
4
5327
by: slapsh0t11 | last post by:
Hello! I need help with a program that I believe I am nearly done with. However, there seems to be a few details that preclude me from success. Here is my assignment: Here is my class file (Sorts.java): import java.util.*; /**
0
9699
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9562
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10305
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10063
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9115
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6838
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5494
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4270
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3792
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.