Thread: i'm having trouble with linked lists

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    To print the numbers forwards instead of backwards, you can recursively transverse the list until you reach the end, and then once you reach the end, print digits and return. All the recursive calls return to where you print the digit, as it percolates up the function frames on the call stack.

    Code:
    void display_number(PNODE pList)
    {
    	if(pList->next != NULL)
    		display_number(pList->next);
    
    	putchar(pList->digit + '0');
    }
    I guess, to make the subtraction work, you have several options, depending on any requirements.

    Code:
    switch(waystodoit)
    {
        case 1: You can make a method to reverse the linked list
        case 2: You can make a method to append to the linked list
            You can use elementary style borrow and carry logic on the linked list
            Or you can make a method to convert the list to an integer, and use the subtraction operator
    }
    That was wierd.

  2. #2
    Registered User
    Join Date
    Jul 2006
    Posts
    12
    lol...well that was an interesting way of giving me options. as for the display of the numbers, i just displayed the two ints for making sure they were getting stored properly...the actual output doesnt require me to display the numbers again, so i dont think it matters if i store them backwards or forwards. also, you say that i can use a method to convert the list to an integer, how can i do that? is there a function for that?

    Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 06-16-2006, 09:23 PM
  2. Linked Lists 101
    By The Brain in forum C++ Programming
    Replies: 5
    Last Post: 07-24-2004, 04:32 PM
  3. Map file formats and linked lists
    By Spitball in forum Game Programming
    Replies: 2
    Last Post: 03-04-2004, 11:32 PM
  4. need help w/ linked lists
    By MKashlev in forum C++ Programming
    Replies: 11
    Last Post: 08-05-2002, 08:57 PM
  5. doubly linked lists
    By qwertiop in forum C++ Programming
    Replies: 3
    Last Post: 10-03-2001, 06:25 PM