Linked list question.

This is a discussion on Linked list question. within the C Programming forums, part of the General Programming Boards category; For $20 dollars, I'll post all 10,000 lines of this engineering wonder. The question comes on how the node gets ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Location
    Berkeley, Ca
    Posts
    195

    Linked list question.

    For $20 dollars, I'll post all 10,000 lines of this engineering wonder. The question comes on how the node gets allocated.

    Code:
    struct node {
     int scores;
     int *next;
    };
    
    typedef N_TYPE n_type;
    
    /*skip 500 lines */
    
    node ->next = malloc(sizeof *node->next);
    Maybe I'm being dense, but why not go something like:

    node->next = malloc(sizeof(struct node));

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Posts
    5,439
    >> For $20 dollars, I'll post all 10,000 lines of this engineering wonder.

    a twenty dollar visual assault? I'll pass.

    >> why not go something like:

    that would be a clearer way to do it.
    Code:
    int main(void){srand(time(0));for(double l=rand(),l0=0,l00=0;;l0+=0.1){for(double l000=0;l000
    <1;l000+=.001,l+=((double)rand()/RAND_MAX)/0x64,l00+=((sin(l*0x8*atan(l0)*l000-(l0*0x8*atan
    (l)))*0.5)+0.5)){l00-=floor(l00);for(size_t l0000=0,l00000=(size_t)(0x50*(l00));l0000<l00000;++l0000
    )putchar(0x20);putchar(0x61+(int)((double)rand()/RAND_MAX*0x1a));putchar('\n');}}return 0;}

  3. #3
    Registered User
    Join Date
    Jan 2006
    Location
    Berkeley, Ca
    Posts
    195
    So going like

    Code:
    node ->next = malloc(sizeof *node->next);
    Is supposed to make the intent more clearer than going something like

    Code:
    node ->next = malloc(sizeof (struct node));

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Posts
    5,439
    no, I meant the other way around.
    Code:
    int main(void){srand(time(0));for(double l=rand(),l0=0,l00=0;;l0+=0.1){for(double l000=0;l000
    <1;l000+=.001,l+=((double)rand()/RAND_MAX)/0x64,l00+=((sin(l*0x8*atan(l0)*l000-(l0*0x8*atan
    (l)))*0.5)+0.5)){l00-=floor(l00);for(size_t l0000=0,l00000=(size_t)(0x50*(l00));l0000<l00000;++l0000
    )putchar(0x20);putchar(0x61+(int)((double)rand()/RAND_MAX*0x1a));putchar('\n');}}return 0;}

  5. #5
    Registered User
    Join Date
    Mar 2006
    Posts
    726
    Depends on what you mean by "clear". I do agree with you on that one, though.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linked List Not Saving Value as Int
    By bar338 in forum C Programming
    Replies: 4
    Last Post: 05-04-2009, 07:53 PM
  2. linked list question
    By brb9412 in forum C Programming
    Replies: 16
    Last Post: 01-04-2009, 03:05 PM
  3. singly linked circular list
    By DarkDot in forum C++ Programming
    Replies: 0
    Last Post: 04-24-2007, 08:55 PM
  4. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM

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