Hey guys, I've had a similar topic before - but this isn't about the fundamental workings of Selection Sort this time.
I am using vectors in correspondence with the selection sort algorithm. (Just for fun and games)...However, I'm getting an annoying error that I cannot think of why it's happening (Because I changed the code around a bit - but this line is deciding to act up now...When it's fundamentally the same as it was before).
Anyhoo - here's the code.
Code:
#include <iostream>
#include <vector>
using namespace std;
int main()
{//Main
vector<int> Selected_Numbers;
int number;
bool quit = false;
int decision;
while(!quit)
{//While
cout<<"(1)Enter a number, or (2)quit, or (3)continue"<<endl;
cin >>decision;
switch (decision)
{//Switch
case 1:
cout<<"What number is it?"<<endl;
cin >>number;
Selected_Numbers.push_back(number);
break;
case 2:
quit = true;
break;
case 3:
int LowestNumber = 0;
int CurrentNumber = 0;
for(vector<int>::iterator iter = Selected_Numbers.begin();
iter != Selected_Numbers.end(); ++iter)
{//For1
CurrentNumber = *iter;
if(LowestNumber <= CurrentNumber)
{//If1
LowestNumber = CurrentNumber;
Selected_Numbers.begin() = LowestNumber;
/*^This is the line generating
the problem. Compiler says
'error C2679: binary '=' :
no operator found
which takes a right-hand
operand of type 'int'
(or there is no acceptable
conversion)' */
}//Close if1
else
{//else1
cout<<"Next Number...."<<endl<<endl;
}//close else1
}//close For1
cout<<"Alrighty then...All has been arranged from lowest - highest"<<endl<<endl;
for(vector<int>::iterator iter = Selected_Numbers.begin();
iter != Selected_Numbers.end(); ++iter)
{//For2
cout<<*iter<<endl;
}//close For 2
break;
}//Close Switch
}//Close While
system("pause");
}//Close Main
Any help will be much appreciated....I do understand what the error says - but I don't know why it's saying it! Cos before, it worked exactly the same (I had to make a change to the code to get Selection Sort to work, by adding the variable 'current number').
- Twigstar