Learn basic concept of c , c++ and python programming in regularcodes.com
Insert node at beginning of linked list
How to insert node at beginning of linked list?. let discussing about all process. what is structure of node:
Data field: how many number of data field are need depends upon your requirement.
Pointer field : how many number of pointer are need. any number are pointer are used here. but normally at least one pointer are compulsory that are pointed to next linked list node.
Here simple linked list node structure are define.
Suppose following data are inserting in linked list. [496, 437, 496, 501, 479, 450, 465, 451, 569, 586 ]. Initially linked list are empty. and linked list root pointer are null. Step by step inserting all linked list node.
Step 1: Create memory block on heap area.
Step 2: Assign data and pointer value.
Step 3: Assign root pointer .
Continuous follow this three step to insert linked list node at start position.
Example: Insert node 496.
Insert another element 437.
Insert another element 496.
Insert another element 501
Insert another element 479.
Insert another element 450
Insert another element 465
Insert another element 451
Insert another element 569
Insert another element 586
In this execution process not imagination all steps. below link click and view how to insert linked list node, how to show all linked list node.
C program to inserting linked list node at beginning.
Case 1: Empty Linked list Output Empty linked List case 2: When linked list are not empty Output Linked list data is : 586 569 451 465 450 479 501 496 437 496 case 3: Free Of linked list Node Free linked list Node element