Thread: Selection Sort problem #2

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Code Monkey
    Join Date
    Jun 2005
    Posts
    25

    Selection Sort problem #2

    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
    Last edited by Twigstar; 07-11-2005 at 06:52 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 01-17-2009, 10:48 PM
  2. Straight Insertion Sort function problem
    By StaticKyle in forum C++ Programming
    Replies: 6
    Last Post: 05-12-2008, 04:03 AM
  3. heap sort problem
    By Cpro in forum C++ Programming
    Replies: 2
    Last Post: 02-04-2008, 04:54 AM
  4. Replies: 5
    Last Post: 11-07-2005, 11:34 PM
  5. Replies: 0
    Last Post: 02-05-2002, 07:44 PM