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

Recommended Answers

All 3 Replies

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());
]

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.