Thread: change the head of linked list question..

  1. #16
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    am i correct?

  2. #17
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    if *p points to elt
    what about the structure of the list

    *p was pointing some other place

    it should ruin the whole structure

    whats happening?
    i debugged this code
    and i cant see whats happening in the end
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    typedef struct node {
        int value;
        struct node *next;
    }Node;
    
    void what1(Node ** p,int num);
    int main()
    {
       Node *p;
       p=(Node *)malloc(sizeof(Node));
       p->value=1;
       p->next=(Node *)malloc(sizeof(Node));
       p->next->value=2;
       what1(&p,0);
       free(p);
        return 0;
    }
    
    void what1(Node ** p,int num)
    {
       Node *elt;
       elt=(Node*)malloc(sizeof(Node));
       elt->next=*p;
       elt->value=num;
        *p=elt;
    }

  3. #18
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    ahhh the link is set by the next members so it doesnt matter

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linked List, Please Help!
    By CodeMonkeyZ in forum C Programming
    Replies: 5
    Last Post: 02-17-2009, 06:23 AM
  2. question about a working linked list
    By cold_dog in forum C++ Programming
    Replies: 23
    Last Post: 09-13-2006, 01:00 AM
  3. Replies: 11
    Last Post: 01-02-2006, 04:46 PM
  4. Replies: 6
    Last Post: 03-02-2005, 02:45 AM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM