Need in sorting



I forgot the codes you need to sort a string of numbers.

EX:
row1 row2 row3
line1: 8 6 3
line2: 3 3 4
line3: 4 7 9


How can I sort row1 from least to greatest? Or row2 etc..


--------------------
Store the numbers in a vector and use the sort() function. If you don't want to do that then you have to create your own function.

Last edited on
How about something like this?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include "stdafx.h"
#include <string>
#include <algorithm>
#include <iostream>

int _tmain(int argc, _TCHAR* argv[])
{
	std::string str("87125");
	// sort it
	std::stable_sort(str.begin(), str.end());

	// print it, should print 12578
	std::cout << str << std::endl;
	return 0;
}
Last edited on
Topic archived. No new replies allowed.