We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,379 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

alphabetic sorting in C++

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++?

3
Contributors
3
Replies
6 Hours
Discussion Span
1 Year Ago
Last Updated
4
Views
kikic
Light Poster
28 posts since Dec 2011
Reputation Points: 7
Solved Threads: 0
Skill Endorsements: 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());
]
Ancient Dragon
Achieved Level 70
Team Colleague
32,145 posts since Aug 2005
Reputation Points: 5,836
Solved Threads: 2,577
Skill Endorsements: 69

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++...

kikic
Light Poster
28 posts since Dec 2011
Reputation Points: 7
Solved Threads: 0
Skill Endorsements: 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

Bench
Posting Pro
577 posts since Feb 2006
Reputation Points: 307
Solved Threads: 63
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0587 seconds using 2.67MB