How to implement linked list using queue data structure?
The One of Most interesting question is why to use queue data structure of linked list. The important factors is they are providing Constant time O(1) to insert linked list element.
Algorithm: Simple step to insert linked list element.
Step 1: Create memory block on heap area.
/* create new memory block using malloc function.*/
struct Node*new_node=(struct Node*)malloc(sizeof(struct Node));
Step 2: Assign data and pointer value.
/*Assign data and next pointer value to newly created node.*/
Step 3: if linked list is empty Assign front and rear pointers to address of newly created node .
/*Assign newly created block address to rear and front pointers. */
*rear=new_node; /*Otherwise do step 4.*/
Step 4 : if linked list are not empty Assign rear pointer to address of newly created node .
/*Assign newly created block address to rear pointer. */
Example : Suppose following data are insert on linked list is[ 44, 35, 34, 75, 635, 623, 23, 36, 66, 62 ].
Linked list basic Animation: View and Edit Linked list Click Here.
Code Executrion Process: Below in show. And more execution process Click Here
Code implementation: Below in C program.
Case 1: Empty Linked list Output Empty linked List case 2: When linked list are not empty Output Linked list data is : 44 35 34 75 636 612 23 36 66 62 Free linked list Node element