I am attempting to take a complex number entered by a user (3-8i or -1+5i) and then sort it in ascending order in the same format as above by real number then imaginary if the same.
I start by asking the user to enter a complex number or ctr-d to terminate the program and then sort. I then want to convert the string to a float. Once a float I want to quick sort it. Is this a proper way of doing this? I know I have a lot of errors.
void QuickSort(vector <float> &vec)
{
quick_sort(vec, 0, vec.size() - 1);
}
void quick_sort (vector<float> &vec, float left, float right){
float pivot, ltemp, rtemp;
ltemp = left;
rtemp = right;
pivot = vec;
while (left < right){
while ((vec >= pivot) && (left < right)){
right--;
}
if (left != right){
vec = vec;
left++;
}
while ((vec <=pivot) && (left < right)) {
left++;
}
if (left != right){
vec = vec;
right--;
}
vec = pivot;
pivot = left;
left = ltemp;
right = rtemp;
if (left < pivot){
quick_sort(vec, left, pivot -1);
}
if (left != right){
vec = vec;
left++;
}
while ((vec <=pivot) && (left < right)) {
left++;
}
if (left != right){
vec = vec;
right--;
}
vec = pivot;
pivot = left;
left = ltemp;
right = rtemp;
if (left < pivot){
quick_sort(vec, left, pivot -1);
}
if (right > pivot){
quick_sort(vec, pivot +1, right);
}
}
int main(){
string user;
vector <float> V;
for (int y = 0; y < 5; y++)
{
cout << "Enter a complex number:" << endl;
cin >> user >> test1;
float usr = atof(user.c_str());
V.push_back(usr);
}
QuickSort(V);
for (int z = 0; z < V.size(); z++)
cout << V[z] << endl;
return 0;
}