sorting a stack--just can't spot the error

This is a discussion on sorting a stack--just can't spot the error within the C++ Programming forums, part of the General Programming Boards category; hey all, i have an array of pointers of which i just want to change the order. i've done this ...

  1. #1
    Registered User blight2c's Avatar
    Join Date
    Mar 2002
    Posts
    266

    sorting a stack--just can't spot the error

    hey all, i have an array of pointers of which i just want to change the order. i've done this before, but somethings not right here and i can't find it (where i'm unsure with if i have the pointers all pointing in the right direction). it does the secondary copy fine, but there's something wrong with copying in to/out from p_temp.
    thanks in advance.

    Code:
    // . . 
    // stack declaration
    Player lineup[15]={*p_h1, *p_h2, *p_h3, *p_h4, *p_h5, *p_h6, *p_h7, *p_h8, *p_h9, *p_h10, 
    					*p_h11, *p_h12, *p_h13, *p_h14, *p_h15};
    
    
    clrscr();
    cout<<endl<<endl<<"In order to play, you must submit your batting order to the umpires."
    	<<endl<<endl<<setw(20)<<"Please wait, while you lineup is loading . . . ";
    f_wait(4);
    
    clrscr();
    f_Lineup_display(lineup);
    	
    cout<<endl<<endl<<endl<<"This is your present batting order."<<endl
    	<<"Would you like to change it, y/n?"<<endl<<"? ";
    cin>>lineup_choice;
    while(lineup_choice=='y')
    {
    	int whoMove=0, 
    		whereMove = 0;
    
    	Player *p_temp;
    
    	clrscr();
    	f_Lineup_display(lineup);
    	cout<<endl<<endl<<endl<<"Enter the number of the player you would like to move:"<<endl;
    	cin>>whoMove;
    	cout<<endl<<"Good, now in what spot should the player be place? (1, 2, 3 . . .)"<<endl;
    	cin>>whereMove;
    	
    	for (int i=0; i<15; i++)
    	{
    		
    
    		if (whoMove == lineup[i].mf_playerStats_getNum())
    		{	p_temp=&lineup[i];
    			lineup[i]=lineup[whereMove-1];
    			lineup[whereMove-1]=*p_temp;//this line isn't doing what
    										//i want :(
    		}
    	}
    // . .

  2. #2
    Registered User matheo917's Avatar
    Join Date
    Sep 2001
    Posts
    279
    i don't see all your code so it's not easy to spot an error especially if it comes to logical errors.......

    try this:

    in your "if" statement on the bottom instead of :

    p_temp = &lineup[i];

    put this:

    p_temp = lineup[i];


    i don't think you should use the address opertor b/c you are assigning lineup[i] (an address tag) which already seems to be a pointer, you can make p_temp point the the whatever lineup[i] is pointing to instead of an address of &lineup[i] ....

    hope i didn't confuse you too much....

    try that...... looks like an interesting solution.....

    Good Luck...
    matheo917

  3. #3
    Registered User blight2c's Avatar
    Join Date
    Mar 2002
    Posts
    266
    thanks for helping out math, i've tried what you suggested before and get the following error:

    error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class Player' (or there is no acceptable conversion)

    but looking at the if statment, that's how you write a normal swap right?

    here's all my code so far--let me know if something is missing
    Attached Files Attached Files

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Avoiding Global variables
    By csonx_p in forum Windows Programming
    Replies: 32
    Last Post: 05-19-2008, 01:17 AM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 07:33 AM
  4. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-30-2005, 12:21 AM
  5. UNICODE and GET_STATE
    By Registered in forum C++ Programming
    Replies: 1
    Last Post: 07-15-2002, 04:23 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21