1,105,450 Community Members

alphabetic sorting in C++

Member Avatar
kikic
Light Poster
28 posts since Dec 2011
Reputation Points: -3 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I made union of two strings with letters. I need to write function in C++ which sort letters in union.

example

union is "acefd"

I need result "acdef"

Could someone help how to write the function for this in C++?

Member Avatar
Ancient Dragon
Achieved Level 70
27,637 posts since Aug 2005
Reputation Points: 5,232 [?]
Q&As Helped to Solve: 3,037 [?]
Skill Endorsements: 115 [?]
Team Colleague
Featured
Sponsor
 
0
 

There are lots of sort algorithms -- google for "bubble sort", which is the easiest one to write. Or you could use cl++ std::sort function.

#include <string>
#include <algorithm>

int main()
{
   std::string s = "acefd";
   std::sort(s.begin(),s.end());
]
Member Avatar
kikic
Light Poster
28 posts since Dec 2011
Reputation Points: -3 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I must not use finite function like that you write me,I need to write function step by step which works for alphabetic sorting in C++...

Member Avatar
Bench
Posting Pro
575 posts since Feb 2006
Reputation Points: 212 [?]
Q&As Helped to Solve: 64 [?]
Skill Endorsements: 0 [?]
 
0
 

I must not use finite function like that you write me,I need to write function step by step which works for alphabetic sorting in C++...

Ancient Dragon's other suggestion was to do a google search for Bubble Sort - try that and you will get plenty of good links which describe how the algorithm works

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: