n*(n+1)'s Profile User Rating: -----

Reputation: 0 Apprentice
Group:
Members
Active Posts:
23 (0.05 per day)
Joined:
13-September 13
Profile Views:
212
Last Active:
User is offline Jan 30 2015 09:24 PM
Currently:
Offline

Previous Fields

Country:
US
OS Preference:
Mac
Favorite Browser:
Chrome
Favorite Processor:
Who Cares
Favorite Gaming Platform:
Who Cares
Your Car:
Who Cares
Dream Kudos:
0
Icon   n*(n+1) has not set their status

Posts I've Made

  1. In Topic: Push linked list pointer problem

    Posted 30 Jan 2015

    Sir,

    I thank you for your patience!
  2. In Topic: Push linked list pointer problem

    Posted 29 Jan 2015

    View PostSkydiver, on 29 January 2015 - 09:23 AM, said:

    View Postn*(n+1), on 28 January 2015 - 11:10 AM, said:

    Sorry for the multiple posts, I tried editing the previous but it wouldn't let me use a certain image extension. Then, I wasn't able to edit at all. But this site clearly explains what happens in memory when doing a push() function with JackOfAllTrades code: http://cslibrary.sta...dListBasics.pdf on page 15. It's called Correct Push() drawing.
    Can anyone explain with the same terms of that drawing, what was happening with what I was trying to do? Help is appreciated, I'm just trying to grasp what is going on.

    I hope this helps with your understanding...
    WrongPush.png



    This helps significantly. Thank you for the illustration. I was picturing head within WrongPushTest() pointing to the node containing one. Now I see how it works. Does the node containing one still exist after WrongPush() executes?
  3. In Topic: Push linked list pointer problem

    Posted 28 Jan 2015

    Sorry for the multiple posts, I tried editing the previous but it wouldn't let me use a certain image extension. Then, I wasn't able to edit at all. But this site clearly explains what happens in memory when doing a push() function with JackOfAllTrades code: http://cslibrary.sta...dListBasics.pdf on page 15. It's called Correct Push() drawing.
    Can anyone explain with the same terms of that drawing, what was happening with what I was trying to do? Help is appreciated, I'm just trying to grasp what is going on.
  4. In Topic: Push linked list pointer problem

    Posted 28 Jan 2015

    View PostSkydiver, on 27 January 2015 - 09:31 PM, said:

    On line 25 you are only changing the the local variable head. Remember that in C, all parameters are passed by value. So when the function was called, it was called with a copy of the root pointer value. Line 25 just changes that local copy.


    This is my problem. I thought I was passing the address of root, not a copy of the value stored at the address. If I understand correctly, the code provided by JackOfAllTrades passes a pointer to a pointer. I guess I'm not seeing why that is necessary when the address is passed.

    Can anyone provide a link to a memory drawing that illustrates what is happening with a pointer to a pointer versus what I was trying to do?

    If not, I'll spend some time just trying to wrap my head around what's going on.

    Thanks for the responses!
  5. In Topic: Push linked list pointer problem

    Posted 27 Jan 2015

    Thanks for the reply. Your code works. I'm misunderstanding pointers. I'd like to write how I thought the code worked and see if anyone can help correct my thinking. My questions are in the code comments.


    int main(int argc, char** argv) {
    
        //node pointer
        struct node *root;
    
         //Points to a memory address? 
        root = malloc(sizeof(struct node));
        
        //Passes memory address that root points to?
        add_end(root, 4);
    }
    
       void add_beg(struct node * head, int val)
        {
        	//New block of memory and new memory address
            struct node * newNode = malloc(sizeof(struct node));
    
            newNode->val = val;
            
            /* The "next" value within the newNode address is set equal to the address
             which root points? */
            newNode->next = head;
            
            /* the address in which root points is set equal to the address of newNode? */
            head = newNode;
           
    
         }
    
    
    


    What trips me up is that root is modified within the add_end function and these changes remain the same outside the function. Root is modified within add_beg as well but is temporary.

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Private

Friends

n*(n+1) hasn't added any friends yet.

Comments

n*(n+1) has no profile comments yet. Why not say hello?