COMPUTER SCIENCE AND ENGINEERING
DATA STRUCTURES
Question
[CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
|
Give syntax to create a node for Single linked list?
|
newnode=(struct node *)malloc(sizeof(struct node*));
|
|
newnode=(struct node )malloc(sizeof(struct node));
|
|
newnode=(struct node *)malloc(sizeof(struct node));
|
|
newnode=(struct node )malloc(sizeof(struct node*));
|
Explanation:
Detailed explanation-1: -struct Node int data; struct Node *next; ; The function insert() inserts the data into the beginning of the linked list. It creates a new node and inserts the number in the data field of the new node. Then the new node points to the head.
Detailed explanation-2: -In C language, a linked list can be implemented using structure and pointers . struct LinkedList int data; struct LinkedList *next; ; The above definition is used to create every node in the list. The data field stores the element and the next is a pointer to store the address of the next node.
There is 1 question to complete.