in Unknown Category
808 views
0 votes
0 votes

in Unknown Category
808 views

1 comment

The correct answer is only B. but both approaches (A and B) seem to be correct
0
0

1 Answer

4 votes
4 votes
Best answer

Implementation B, is the correct one. 

If you modify Implementation One following then it will also work correctly.

Node *insert (Node * head, int data){
    Node *newNode = (Node *)malloc(sizeof(Node));
    newNode -> data = data;
    newNode -> next = head;
    head = newNode;
    return head;
}

Implementation B is working correctly just because you are passing the address of head pointer, hence its can be updated from insert function, we do not need to return the value.

selected by
by

Related questions