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.
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').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
- Twigstar



LinkBack URL
About LinkBacks



) arithmitic! Damn...So I just check the next element up in the same go, compare it, and then swap if true. And then +1 to the iter...Ok, I'll give it a bash - cheers 'IloveVectors'(What an appropiate name for this situation, lol)...I'd still like to know how that 1 got there instead of the three though, lol