Assignment operator help.

This is a discussion on Assignment operator help. within the C++ Programming forums, part of the General Programming Boards category; Code: if (current==start_ptr) cout<<"you are at the end of the list"<<endl; else { node *previous; //declare pointer previous=start=start_ptr; while (previous->nxt ...

  1. #1
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427

    Assignment operator help.

    Code:
    if (current==start_ptr)
              cout<<"you are at the end of the list"<<endl;
    else 
    { node *previous; //declare pointer
       previous=start=start_ptr;
    
        while (previous->nxt !=current)
             {   previous=previous->nxt;
              }
    current=previous; // would this work the same if it
    were previous=current?
    }

    //This is just to gain access no a previous node on a linked list
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    That should work, but it would be much simpler to just have a whisker pointer to feel ahead of current and you can use current to read the values.
    Code:
    node *current = head, *whisker = current->next;
    while ( whisker != start_ptr ) {
      if ( whisker->key == someValue ) {
        cout<<current->value<<endl; 
        break;
      }
      else
        current = whisker; whisker = current->next;
    }
    The whisker is also immensely useful in deleting a node in a single linked list.

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Menu
    By Krush in forum C Programming
    Replies: 17
    Last Post: 09-01-2009, 03:34 AM
  2. Assignment Operator, Memory and Scope
    By SevenThunders in forum C++ Programming
    Replies: 47
    Last Post: 03-31-2008, 07:22 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  4. Help with a pretty big C++ assignment
    By wakestudent988 in forum C++ Programming
    Replies: 1
    Last Post: 10-30-2006, 09:46 PM
  5. Replies: 1
    Last Post: 10-27-2006, 02:21 PM

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