Thread: Assignment operator help.

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

    Assignment operator help.

    if (current==start_ptr)
              cout<<"you are at the end of the list"<<endl;
    { node *previous; //declare pointer
        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
    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.
    node *current = head, *whisker = current->next;
    while ( whisker != start_ptr ) {
      if ( whisker->key == someValue ) {
        current = whisker; whisker = current->next;
    The whisker is also immensely useful in deleting a node in a single linked list.

    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, 02:34 AM
  2. Assignment Operator, Memory and Scope
    By SevenThunders in forum C++ Programming
    Replies: 47
    Last Post: 03-31-2008, 06:22 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02: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, 01:21 PM