473,379 Members | 1,283 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Quicksort for list of string

can any one tell me if I give the followiing string in input:
ABC
abc
BBC

then how I can get
ABC
abc
BBC
or

abc
ABC
BBC
as my output usiing quicksort.

Apr 19 '07 #1
12 4350
On 19 Apr, 13:50, aparnakakkar2...@gmail.com wrote:
can any one tell me if I give the followiing string in input:
ABC
abc
BBC

then how I can get
ABC
abc
BBC

or

abc
ABC
BBC
as my output usiing quicksort.
Don't know about quicksort but if it's sorting you want then given a
number of strings read from some input store them in a std::vector and
use std::sort() on them. Don't know the exact ordering of strings but
I'd guess that capital letters are sorted before lowercase letters so
the most likely result would be:

ABC
abc
BBC

--
Erik Wikström

Apr 19 '07 #2
Erik Wikström wrote:
On 19 Apr, 13:50, aparnakakkar2...@gmail.com wrote:
>can any one tell me if I give the followiing string in input:
ABC
abc
BBC

then how I can get
ABC
abc
BBC

or

abc
ABC
BBC
as my output usiing quicksort.

Don't know about quicksort but if it's sorting you want then given a
number of strings read from some input store them in a std::vector and
use std::sort() on them. Don't know the exact ordering of strings but
I'd guess that capital letters are sorted before lowercase letters so
the most likely result would be:

ABC
abc
BBC
*All* capital letters come before *any* lowercase ones. So, the result
*should* be

ABC
BBC
abc

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Apr 19 '07 #3
On Apr 19, 6:42 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
Erik Wikström wrote:
On 19 Apr, 13:50, aparnakakkar2...@gmail.com wrote:
can any one tell me if I give the followiing string in input:
ABC
abc
BBC
then how I can get
ABC
abc
BBC
or
abc
ABC
BBC
as my output usiing quicksort.
Don't know about quicksort but if it's sorting you want then given a
number of strings read from some input store them in a std::vector and
use std::sort() on them. Don't know the exact ordering of strings but
I'd guess that capital letters are sorted before lowercase letters so
the most likely result would be:
ABC
abc
BBC

*All* capital letters come before *any* lowercase ones. So, the result
*should* be

ABC
BBC
abc

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask- Hide quoted text -

- Show quoted text -
but I want in that way only can you tell me how ,that sort function
will not give this result.

Apr 19 '07 #4
ap**************@gmail.com wrote:
On Apr 19, 6:42 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
>Erik Wikström wrote:
>>On 19 Apr, 13:50, aparnakakkar2...@gmail.com wrote:
can any one tell me if I give the followiing string in input:
ABC
abc
BBC
>>>then how I can get
ABC
abc
BBC
>>>or
>>>abc
ABC
BBC
as my output usiing quicksort.
>>Don't know about quicksort but if it's sorting you want then given a
number of strings read from some input store them in a std::vector
and use std::sort() on them. Don't know the exact ordering of
strings but I'd guess that capital letters are sorted before
lowercase letters so the most likely result would be:
>>ABC
abc
BBC

*All* capital letters come before *any* lowercase ones. So, the
result
*should* be

ABC
BBC
abc

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask- Hide
quoted text -

- Show quoted text -

but I want in that way only can you tell me how ,that sort function
will not give this result.
Well, I wasn't replying to you, I was replyting to Erik.

And, sorry, I don't understand the last sentence you posted. Could
you perhaps rephrase it using a few shorter sentences?

Neither C++ strings (objects of type 'std::string') nor C strings
(arrays of char) can be sorted using 'quicksort' (generally speaking).

To sort 'std::string' objects, use 'std::sort' (which most likely
implements Quick Sort algorithm), or the 'sort' member of the 'list'
container (if your strings are in a 'list' container).

In order to use 'qsort' function, you'd have to define your own
data structures, your own comparator, and then place your data in
an array, and then call 'qsort'. If that's your how you want to do
that, fine; it's not the best C++ way, however.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Apr 19 '07 #5
<ap**************@gmail.comwrote in message
news:11*********************@p77g2000hsh.googlegro ups.com...
can any one tell me if I give the followiing string in input:
ABC
abc
BBC

then how I can get
ABC
abc
BBC
or

abc
ABC
BBC
as my output usiing quicksort.
Well, this doesn't use quicksort but std::sort which is O( N log N ).

Output is:

Before sort:
ABC
abc
BBC
ABCD
aB

After sort:
ABC
ABCD
BBC
aB
abc

After Case Insensitive sort:
aB
ABC
abc
ABCD
BBC

There may be a better/faster algorithm for the case insensitve comparing of
std::strings. I just did this one rather quickly.

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cctype>

bool CILessthan( const std::string Elem1, const std::string Elem2 )
{
for ( std::size_t i = 0; i < Elem1.length(); ++i )
{
if ( std::tolower( Elem1[i] ) < std::tolower( Elem2[i] ) )
return true;
else if ( std::tolower( Elem1[i] ) std::tolower( Elem2[i] ) )
return false;
}

// Equal up to this point, but one may be longer
if ( Elem1.length() < Elem2.length() )
return true;

return false;
}

void ShowData( const std::vector<std::string>& Data )
{
for ( std::vector<std::string>::const_iterator it = Data.begin(); it !=
Data.end(); ++it )
std::cout << (*it) << "\n";
}

int main()
{
std::vector<std::stringData;
Data.push_back( "ABC" );
Data.push_back( "abc" );
Data.push_back( "BBC" );
Data.push_back( "ABCD" );
Data.push_back( "aB" );

std::cout << "Before sort:\n";
ShowData( Data );

std::sort( Data.begin(), Data.end() );
std::cout << "\nAfter sort:\n";
ShowData( Data );

std::sort( Data.begin(), Data.end(), CILessthan );
std::cout << "\nAfter Case Insensitive sort:\n";
ShowData( Data );

std::string wait;
std::getline( std::cin, wait );
}
Apr 19 '07 #6
On Apr 19, 8:20 pm, "Jim Langston" <tazmas...@rocketmail.comwrote:
<aparnakakkar2...@gmail.comwrote in message

news:11*********************@p77g2000hsh.googlegro ups.com...


can any one tell me if I give the followiing string in input:
ABC
abc
BBC
then how I can get
ABC
abc
BBC
or
abc
ABC
BBC
as my output usiing quicksort.

Well, this doesn't use quicksort but std::sort which is O( N log N ).

Output is:

Before sort:
ABC
abc
BBC
ABCD
aB

After sort:
ABC
ABCD
BBC
aB
abc

After Case Insensitive sort:
aB
ABC
abc
ABCD
BBC

There may be a better/faster algorithm for the case insensitve comparing of
std::strings. I just did this one rather quickly.

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cctype>

bool CILessthan( const std::string Elem1, const std::string Elem2 )
{
for ( std::size_t i = 0; i < Elem1.length(); ++i )
{
if ( std::tolower( Elem1[i] ) < std::tolower( Elem2[i] ) )
return true;
else if ( std::tolower( Elem1[i] ) std::tolower( Elem2[i] ) )
return false;
}

// Equal up to this point, but one may be longer
if ( Elem1.length() < Elem2.length() )
return true;

return false;

}

void ShowData( const std::vector<std::string>& Data )
{
for ( std::vector<std::string>::const_iterator it = Data.begin(); it !=
Data.end(); ++it )
std::cout << (*it) << "\n";

}

int main()
{
std::vector<std::stringData;
Data.push_back( "ABC" );
Data.push_back( "abc" );
Data.push_back( "BBC" );
Data.push_back( "ABCD" );
Data.push_back( "aB" );

std::cout << "Before sort:\n";
ShowData( Data );

std::sort( Data.begin(), Data.end() );
std::cout << "\nAfter sort:\n";
ShowData( Data );

std::sort( Data.begin(), Data.end(), CILessthan );
std::cout << "\nAfter Case Insensitive sort:\n";
ShowData( Data );

std::string wait;
std::getline( std::cin, wait );

}- Hide quoted text -

- Show quoted text -- Hide quoted text -

- Show quoted text -
please tell me how is it possible with (std::list<std::stringdata)
as an argument

Apr 19 '07 #7
<ap**************@gmail.comwrote in message
news:11**********************@n76g2000hsh.googlegr oups.com...
On Apr 19, 8:20 pm, "Jim Langston" <tazmas...@rocketmail.comwrote:
><aparnakakkar2...@gmail.comwrote in message

news:11*********************@p77g2000hsh.googlegr oups.com...


can any one tell me if I give the followiing string in input:
ABC
abc
BBC
then how I can get
ABC
abc
BBC
or
abc
ABC
BBC
as my output usiing quicksort.

Well, this doesn't use quicksort but std::sort which is O( N log N ).

Output is:

Before sort:
ABC
abc
BBC
ABCD
aB

After sort:
ABC
ABCD
BBC
aB
abc

After Case Insensitive sort:
aB
ABC
abc
ABCD
BBC

There may be a better/faster algorithm for the case insensitve comparing
of
std::strings. I just did this one rather quickly.

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cctype>

bool CILessthan( const std::string Elem1, const std::string Elem2 )
{
for ( std::size_t i = 0; i < Elem1.length(); ++i )
{
if ( std::tolower( Elem1[i] ) < std::tolower( Elem2[i] ) )
return true;
else if ( std::tolower( Elem1[i] ) std::tolower( Elem2[i] ) )
return false;
}

// Equal up to this point, but one may be longer
if ( Elem1.length() < Elem2.length() )
return true;

return false;

}

void ShowData( const std::vector<std::string>& Data )
{
for ( std::vector<std::string>::const_iterator it = Data.begin(); it
!=
Data.end(); ++it )
std::cout << (*it) << "\n";

}

int main()
{
std::vector<std::stringData;
Data.push_back( "ABC" );
Data.push_back( "abc" );
Data.push_back( "BBC" );
Data.push_back( "ABCD" );
Data.push_back( "aB" );

std::cout << "Before sort:\n";
ShowData( Data );

std::sort( Data.begin(), Data.end() );
std::cout << "\nAfter sort:\n";
ShowData( Data );

std::sort( Data.begin(), Data.end(), CILessthan );
std::cout << "\nAfter Case Insensitive sort:\n";
ShowData( Data );

std::string wait;
std::getline( std::cin, wait );

}- Hide quoted text -

- Show quoted text -- Hide quoted text -

- Show quoted text -

please tell me how is it possible with (std::list<std::stringdata)
as an argument
Just replace
std::sort( Data.begin(), Data.end(); CILessthan );
with
Data.sort( CILessthan );

As long as it's a list and not a vector.
Apr 19 '07 #8
On Apr 19, 3:42 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
Erik Wikström wrote:
On 19 Apr, 13:50, aparnakakkar2...@gmail.com wrote:
can any one tell me if I give the followiing string in input:
ABC
abc
BBC
then how I can get
ABC
abc
BBC
or
abc
ABC
BBC
as my output usiing quicksort.
Don't know about quicksort but if it's sorting you want then given a
number of strings read from some input store them in a std::vector and
use std::sort() on them. Don't know the exact ordering of strings but
I'd guess that capital letters are sorted before lowercase letters so
the most likely result would be:
ABC
abc
BBC
*All* capital letters come before *any* lowercase ones.
That's actually platform dependant (and so off-topic here:-).
On an IBM mainframe, capital letters come after lowercase (and
there are some punctuation signs which show up in the middle of
the alphabet). On my system (Solaris), some of the capitals
even have negative values---forcing them to an unsigned char
results in two blocks of capitals, and two of small letters,
interleaved (with some punctuation and some control characters
between them).

That's why when the order is significant to a human being,
you'll almost always use a locale specific collating function.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Apr 19 '07 #9
On Apr 19, 10:21 pm, James Kanze <james.ka...@gmail.comwrote:
On Apr 19, 3:42 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:


Erik Wikström wrote:
On 19 Apr, 13:50, aparnakakkar2...@gmail.com wrote:
>can any one tell me if I give the followiing string in input:
>ABC
>abc
>BBC
>then how I can get
>ABC
>abc
>BBC
>or
>abc
>ABC
>BBC
>as my output usiing quicksort.
Don't know about quicksort but if it's sorting you want then given a
number of strings read from some input store them in a std::vector and
use std::sort() on them. Don't know the exact ordering of strings but
I'd guess that capital letters are sorted before lowercase letters so
the most likely result would be:
ABC
abc
BBC
*All* capital letters come before *any* lowercase ones.

That's actually platform dependant (and so off-topic here:-).
On an IBM mainframe, capital letters come after lowercase (and
there are some punctuation signs which show up in the middle of
the alphabet). On my system (Solaris), some of the capitals
even have negative values---forcing them to an unsigned char
results in two blocks of capitals, and two of small letters,
interleaved (with some punctuation and some control characters
between them).

That's why when the order is significant to a human being,
you'll almost always use a locale specific collating function.

--
James Kanze (GABI Software) email:james.ka...@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34- Hide quoted text -

- Show quoted text -
can any one tell me i f the code below will work or not

void QuickSortList(VR_STRINGList::iterator
pLeft,VR_STRINGList::iterator pRight)
{
VR_STRINGList ::iterator pStart;
VR_STRINGList ::iterator pCurrent;
// VR_STRINGList ::iterator nCopyInteger; // If the left and
right pointers are the same, then return

VR_STRING nCopyInteger;

if (pLeft == pRight)
return;

pStart = pLeft;
pCurrent = pStart++; // Loop forever (well until we get to the
right)
while (1)
{
if(strcmpi(pStart->c_str(),pCurrent->c_str())<0)
{
nCopyInteger = *pCurrent;
*pCurrent = *pStart;
*pStart = nCopyInteger;
}
if (pCurrent == pRight)
break;
pCurrent = pCurrent++;
}

nCopyInteger = *pLeft;
*pLeft = *pCurrent;
*pCurrent= nCopyInteger;

VR_STRINGList ::iterator pOldCurrent;
*pOldCurrent = *pCurrent;
pCurrent = pCurrent--;

if (pCurrent != NULL)
{
if ((pLeft-- != pCurrent) && (pCurrent++ != pLeft))
QuickSortList(pLeft,pCurrent);
}

pCurrent = pOldCurrent;
pCurrent = pCurrent++;
if (pCurrent != NULL)
{
if ((pCurrent-- != pRight) && (pRight++ != pCurrent))
QuickSortList(pCurrent, pRight);
}
}
Tell me problem please I am not getting the output.

Apr 20 '07 #10
On Apr 19, 9:48 pm, "Jim Langston" <tazmas...@rocketmail.comwrote:
<aparnakakkar2...@gmail.comwrote in message

news:11**********************@n76g2000hsh.googlegr oups.com...
On Apr 19, 8:20 pm, "Jim Langston" <tazmas...@rocketmail.comwrote:
<aparnakakkar2...@gmail.comwrote in message
>news:11*********************@p77g2000hsh.googlegr oups.com...
can any one tell me if I give the followiing string in input:
ABC
abc
BBC
then how I can get
ABC
abc
BBC
or
abc
ABC
BBC
as my output usiing quicksort.
Well, this doesn't use quicksort but std::sort which is O( N log N ).
Output is:
Before sort:
ABC
abc
BBC
ABCD
aB
After sort:
ABC
ABCD
BBC
aB
abc
After Case Insensitive sort:
aB
ABC
abc
ABCD
BBC
There may be a better/faster algorithm for the case insensitve
comparing
of
std::strings. I just did this one rather quickly.
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cctype>
bool CILessthan( const std::string Elem1, const std::string Elem2 )
{
for ( std::size_t i = 0; i < Elem1.length(); ++i )
{
if ( std::tolower( Elem1[i] ) < std::tolower( Elem2[i] ) )
return true;
else if ( std::tolower( Elem1[i] ) std::tolower( Elem2[i] ) )
return false;
}
// Equal up to this point, but one may be longer
if ( Elem1.length() < Elem2.length() )
return true;
return false;
}
void ShowData( const std::vector<std::string>& Data )
{
for ( std::vector<std::string>::const_iterator it = Data.begin();
it
!=
Data.end(); ++it )
std::cout << (*it) << "\n";
}
int main()
{
std::vector<std::stringData;
Data.push_back( "ABC" );
Data.push_back( "abc" );
Data.push_back( "BBC" );
Data.push_back( "ABCD" );
Data.push_back( "aB" );
std::cout << "Before sort:\n";
ShowData( Data );
std::sort( Data.begin(), Data.end() );
std::cout << "\nAfter sort:\n";
ShowData( Data );
std::sort( Data.begin(), Data.end(), CILessthan );
std::cout << "\nAfter Case Insensitive sort:\n";
ShowData( Data );
std::string wait;
std::getline( std::cin, wait );
}- Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -
please tell me how is it possible with (std::list<std::stringdata)
as an argument

Just replace
std::sort( Data.begin(), Data.end(); CILessthan );
with
Data.sort( CILessthan );

As long as it's a list and not a vector.- Hide quoted text -
Its not working I want Data to be of type " std::list<std::string>
Data;"

--------

Please don't send questions to my e-mail, post them here.

In this program if you replace every occurance of "vector" with "list",
change
std::sort( Data.begin(), Data.end(); CILessthan );
with
Data.sort( CILessthan );

and compile it should run fine.
Apr 20 '07 #11
On Apr 20, 8:37 am, "Jim Langston" <tazmas...@rocketmail.comwrote:
On Apr 19, 9:48 pm, "Jim Langston" <tazmas...@rocketmail.comwrote:


<aparnakakkar2...@gmail.comwrote in message
news:11**********************@n76g2000hsh.googlegr oups.com...
On Apr 19, 8:20 pm, "Jim Langston" <tazmas...@rocketmail.comwrote:
><aparnakakkar2...@gmail.comwrote in message
>>news:11*********************@p77g2000hsh.googleg roups.com...
can any one tell me if I give the followiing string in input:
ABC
abc
BBC
then how I can get
ABC
abc
BBC
or
abc
ABC
BBC
as my output usiing quicksort.
>Well, this doesn't use quicksort but std::sort which is O( N log N ).
>Output is:
>Before sort:
>ABC
>abc
>BBC
>ABCD
>aB
>After sort:
>ABC
>ABCD
>BBC
>aB
>abc
>After Case Insensitive sort:
>aB
>ABC
>abc
>ABCD
>BBC
>There may be a better/faster algorithm for the case insensitve
>comparing
>of
>std::strings. I just did this one rather quickly.
>#include <iostream>
>#include <string>
>#include <vector>
>#include <algorithm>
>#include <cctype>
>bool CILessthan( const std::string Elem1, const std::string Elem2 )
>{
> for ( std::size_t i = 0; i < Elem1.length(); ++i )
> {
> if ( std::tolower( Elem1[i] ) < std::tolower( Elem2[i] ) )
> return true;
> else if ( std::tolower( Elem1[i] ) std::tolower( Elem2[i] ) )
> return false;
> }
> // Equal up to this point, but one may be longer
> if ( Elem1.length() < Elem2.length() )
> return true;
> return false;
>}
>void ShowData( const std::vector<std::string>& Data )
>{
> for ( std::vector<std::string>::const_iterator it = Data.begin();
>it
>!=
>Data.end(); ++it )
> std::cout << (*it) << "\n";
>}
>int main()
>{
> std::vector<std::stringData;
> Data.push_back( "ABC" );
> Data.push_back( "abc" );
> Data.push_back( "BBC" );
> Data.push_back( "ABCD" );
> Data.push_back( "aB" );
> std::cout << "Before sort:\n";
> ShowData( Data );
> std::sort( Data.begin(), Data.end() );
> std::cout << "\nAfter sort:\n";
> ShowData( Data );
> std::sort( Data.begin(), Data.end(), CILessthan );
> std::cout << "\nAfter Case Insensitive sort:\n";
> ShowData( Data );
> std::string wait;
> std::getline( std::cin, wait );
>}- Hide quoted text -
>- Show quoted text -- Hide quoted text -
>- Show quoted text -
please tell me how is it possible with (std::list<std::stringdata)
as an argument
Just replace
std::sort( Data.begin(), Data.end(); CILessthan );
with
Data.sort( CILessthan );
As long as it's a list and not a vector.- Hide quoted text -

Its not working I want Data to be of type " std::list<std::string>
Data;"

--------

Please don't send questions to my e-mail, post them here.

In this program if you replace every occurance of "vector" with "list",
change
std::sort( Data.begin(), Data.end(); CILessthan );
with
Data.sort( CILessthan );

and compile it should run fine.- Hide quoted text -

- Show quoted text -
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cctype>

#include <list>
#include <iostream>
using namespace std ;
typedef list<stringVR_STRINGList;
bool CILessthan( std::list<std::string>::iterator Elem1,
std::list<std::string>::iterator Elem2 )
{
//std::list<std::string::iterator i;
int i;
int arrayLength = Elem1->length();
for ( i = 0; i < arrayLength; ++i )
{
if ( strcmp(Elem1->c_str(),Elem2->c_str())<=0 )
return true;
else if ( strcmp(Elem1->c_str(), Elem2->c_str())>0)
return false;
}
// Equal up to this point, but one may be longer
if ( Elem1->length() < Elem2->length())
return true;
return false;

}

void ShowData( const std::list<std::string>& Data )
{
for ( std::list<std::string>::const_iterator it = Data.begin();
it != Data.end(); ++it )
std::cout << (*it) << "\n";
}

int main()
{
std::list<std::stringData;
Data.push_back( "ABC" );
Data.push_back( "abc" );
Data.push_back( "BBC" );
std::cout << "Before sort:\n";
ShowData( Data );
// std::sort( Data.begin(), Data.end() );
std::cout << "\nAfter sort:\n";
ShowData( Data );

// std::sort( Data.begin(), Data.end(), CILessthan );
Data.sort(CILessthan);
std::cout << "\nAfter Case Insensitive sort:\n";
ShowData( Data );
std::string wait;
std::getline( std::cin, wait );
}
I have done changes above for list but still getting error

Apr 20 '07 #12
On Apr 20, 8:37 am, "Jim Langston" <tazmas...@rocketmail.comwrote:
On Apr 19, 9:48 pm, "Jim Langston" <tazmas...@rocketmail.comwrote:


<aparnakakkar2...@gmail.comwrote in message
news:11**********************@n76g2000hsh.googlegr oups.com...
On Apr 19, 8:20 pm, "Jim Langston" <tazmas...@rocketmail.comwrote:
><aparnakakkar2...@gmail.comwrote in message
>>news:11*********************@p77g2000hsh.googleg roups.com...
can any one tell me if I give the followiing string in input:
ABC
abc
BBC
then how I can get
ABC
abc
BBC
or
abc
ABC
BBC
as my output usiing quicksort.
>Well, this doesn't use quicksort but std::sort which is O( N log N ).
>Output is:
>Before sort:
>ABC
>abc
>BBC
>ABCD
>aB
>After sort:
>ABC
>ABCD
>BBC
>aB
>abc
>After Case Insensitive sort:
>aB
>ABC
>abc
>ABCD
>BBC
>There may be a better/faster algorithm for the case insensitve
>comparing
>of
>std::strings. I just did this one rather quickly.
>#include <iostream>
>#include <string>
>#include <vector>
>#include <algorithm>
>#include <cctype>
>bool CILessthan( const std::string Elem1, const std::string Elem2 )
>{
> for ( std::size_t i = 0; i < Elem1.length(); ++i )
> {
> if ( std::tolower( Elem1[i] ) < std::tolower( Elem2[i] ) )
> return true;
> else if ( std::tolower( Elem1[i] ) std::tolower( Elem2[i] ) )
> return false;
> }
> // Equal up to this point, but one may be longer
> if ( Elem1.length() < Elem2.length() )
> return true;
> return false;
>}
>void ShowData( const std::vector<std::string>& Data )
>{
> for ( std::vector<std::string>::const_iterator it = Data.begin();
>it
>!=
>Data.end(); ++it )
> std::cout << (*it) << "\n";
>}
>int main()
>{
> std::vector<std::stringData;
> Data.push_back( "ABC" );
> Data.push_back( "abc" );
> Data.push_back( "BBC" );
> Data.push_back( "ABCD" );
> Data.push_back( "aB" );
> std::cout << "Before sort:\n";
> ShowData( Data );
> std::sort( Data.begin(), Data.end() );
> std::cout << "\nAfter sort:\n";
> ShowData( Data );
> std::sort( Data.begin(), Data.end(), CILessthan );
> std::cout << "\nAfter Case Insensitive sort:\n";
> ShowData( Data );
> std::string wait;
> std::getline( std::cin, wait );
>}- Hide quoted text -
>- Show quoted text -- Hide quoted text -
>- Show quoted text -
please tell me how is it possible with (std::list<std::stringdata)
as an argument
Just replace
std::sort( Data.begin(), Data.end(); CILessthan );
with
Data.sort( CILessthan );
As long as it's a list and not a vector.- Hide quoted text -

Its not working I want Data to be of type " std::list<std::string>
Data;"

--------

Please don't send questions to my e-mail, post them here.

In this program if you replace every occurance of "vector" with "list",
change
std::sort( Data.begin(), Data.end(); CILessthan );
with
Data.sort( CILessthan );

and compile it should run fine.- Hide quoted text -

- Show quoted text -
Thanks,its working fine.

Apr 20 '07 #13

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

Similar topics

5
by: why | last post by:
Hi, just been curious. i have learn that quicksorting algorithm is more widely used then heapsort, despite having the same performance indication of O(n log n) anyone knows why? newbie
2
by: nkharan | last post by:
Hey, Here is the pseudocode of quicksort. It can be observed that there are as many as (n-1) unresolved stack calls in the worst case. Now, how do i reduce this unresolved stack calls? what...
6
by: Baltazar007 | last post by:
Does anyone know how to make quicksort for single linked list without using array? I know that mergesort is maybe better but I need quicksort!! thnx
8
by: aparnakakkar2003 | last post by:
hello can any one tell me how i can create program to sort string list(standard template library) using quicksort.
8
by: aparnakakkar2003 | last post by:
hello can any one tell me how i can create program to sort string list(standard template library) using quicksort.
3
by: jollyfolly | last post by:
Could you please help me find the error. I myself have (i might be wrong) boiled it down to the for loop because it somehow magically converts a list into an int and tries to iterate over that. But I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.