5. Consider the following data structure: Struct node { Int data; Struct node *n
ID: 3560914 • Letter: 5
Question
5. Consider the following data structure: Struct node { Int data; Struct node *next; }; typedef struct node Node; Implement the function print below, which traverses a linked list and prints the data values of the items in the list to standard output. Void printList (Node *head) { /* write the function body */ } Consider the following two functions declarations for appending a node with a given value to the end of a linked list. Which one is the correct declaration and why? Void appendItem(Node *head, int value); Void appendItem(Node **head, int value);Explanation / Answer
1)
void printList(Node *head)
{
Node *q=head;
while(q!=NULL)
{
cout<<q->data;
q=q->next;
}
}
2)
void appendItem(Node *head,int value)
*head contains the address of the fist node of the linked list, this address can be used to access all the nodes of the linked list.
whereas **head contains the address to the *head pointer.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.