Matthew wrote:I don't know how to return vectors.
*faint*
Matthew wrote:To return an array I'd use a pointer.
I want a dynamic amount of data to be collected so I'm stuck with a vector.
EDIT:
I have looked at quick sort. It's pretty neat! Damn programming is cool

Anyway, as you know, I have a difficulty with recursion but before that here is what I have:
Code: Select all
#include <iostream>
#include <vector>
using namespace std;
vector <char> mySort(vector <char> Letters);
int main()
{
vector <char> Chars;
vector <char> CharsSorted;
char chars = 97;
for (int i = 0; i < 10; i++)
{
Chars.push_back(chars);
chars++;
}
Chars = mySort(Chars);
for (int i = 0; i < Chars.size(); i++)
cout << Chars[i] << ", ";
return 0;
}
vector <char> mySort(vector <char> Letters)
{
vector <char> Less;
vector <char> Greater;
Less.reserve(Letters.size());
Greater.reserve(Letters.size());
for (int i = 1; i < Letters.size()-1; i++)//A
{
if (Letters[Letters.size()] > Letters.size()-i)
Less.insert(Less.begin(), Letters[Letters.size()-1]);
Letters.erase(Letters.end()-1);
}
for (int i = 0; i < Letters.size(); i++)//B
{
Greater.push_back(Letters[i]);
}
for (int i = 1; i > Letters.size()-1; i++)//A
{
if (Letters[Letters.size()] > Letters.size()-i)
Greater.insert(Greater.begin(), Letters[Letters.size()-1]);
Letters.erase(Letters.end()-1);
}
for (int i = Greater.size()-1; i > -1; i--)//B
Less.insert(Less.begin(), Greater[i]);
return Less;
}
The A and B comments are for parts that I think I can make reoccur. I am really tired right now so my mind isn't thinking properly but I just wanted to share what I did.
On a related note: what is the fastest sorting method? How do you understand the worst, best, average case symbols and equations? Thanks
