for example
"How are you"
will be
Haeooruwy
here is what I have so far
however it does not seem to sort the string but rather output it exactly what was inputted:
for example when i input "Hey guys" it will output Hey guys but that is not what i want it to output
thanks in advance
#include <iostream>
#include <vector>
#include <cstdlib>
#include <string>
using namespace std;
void selSort(vector<string>& v);
int main()
{
int answer;
vector<string> v;
string next;
getline(cin, next);
v.push_back(next);
selSort(v);
for (int i= 0; i < v.size(); i++)
cout << v[i] << ' ';
cout << endl;
getchar ();
return 0;
}
void selSort(vector<string>& v)
{
for (int pass=0; pass<v.size()-1; pass++) {
int potentialSmallest = pass;
for (int i=pass+1; i<v.size(); i++) {
if (v[i] < v[potentialSmallest]) {
potentialSmallest = i;
}
}
string temp = v[pass];
v[pass] = v[potentialSmallest];
v[potentialSmallest] = temp;
}
}

New Topic/Question
Reply




MultiQuote




|