Create Linked List

Node* Create()
{
    int input;
    Node *p0, *p1, *head;
    p0 = (Node*)malloc(sizeof(Node));                      // create a dummy head
    p1 = p0;
 
    while (scanf("%d", &input)) {
        p1->next = (Node*)malloc(sizeof(Node));
        p1 = p1->next;
        p1->data = input;
    }
 
    p1->next = NULL;                                         // kill the dummy head now
    head = p0->next;
    free(p0);
 
    return head;
}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License