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. 12 4389
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
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
On Apr 19, 6:42 pm, "Victor Bazarov" <v.Abaza...@com Acast.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. ap************* *@gmail.com wrote:
On Apr 19, 6:42 pm, "Victor Bazarov" <v.Abaza...@com Acast.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
<ap************ **@gmail.comwro te in message
news:11******** *************@p 77g2000hsh.goog legroups.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>::cons t_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 );
}
On Apr 19, 8:20 pm, "Jim Langston" <tazmas...@rock etmail.comwrote :
<aparnakakkar2. ..@gmail.comwro te in message
news:11******** *************@p 77g2000hsh.goog legroups.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>::cons t_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
<ap************ **@gmail.comwro te in message
news:11******** **************@ n76g2000hsh.goo glegroups.com.. .
On Apr 19, 8:20 pm, "Jim Langston" <tazmas...@rock etmail.comwrote :
><aparnakakkar2 ...@gmail.comwr ote in message
news:11******* **************@ p77g2000hsh.goo glegroups.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>::cons t_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.
On Apr 19, 3:42 pm, "Victor Bazarov" <v.Abaza...@com Acast.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 objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
On Apr 19, 10:21 pm, James Kanze <james.ka...@gm ail.comwrote:
On Apr 19, 3:42 pm, "Victor Bazarov" <v.Abaza...@com Acast.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 objektorientier ter Datenverarbeitu ng
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(V R_STRINGList::i terator
pLeft,VR_STRING List::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(pSta rt->c_str(),pCurre nt->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(p Left,pCurrent);
}
pCurrent = pOldCurrent;
pCurrent = pCurrent++;
if (pCurrent != NULL)
{
if ((pCurrent-- != pRight) && (pRight++ != pCurrent))
QuickSortList(p Current, pRight);
}
}
Tell me problem please I am not getting the output. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
|
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 modifications should I
make?
procedure QuickSort(L, low, high) recursive
Input: L (a list of size n), low, high (integers)
Output: L is sorted
if high > low then
|
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
|
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.
|
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.
| |
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 don't know how to fix it, doesn't even make sense why it would do it. Please help me out. Thanks in advance!
Here is the error it gives me:
TypeError: 'int' object is not iterable
Here is my code:
import random
|
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,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
| |
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |