Posts

Showing posts from February, 2020

Linked List II

Image
Linked List Head : address of the head node gives us access of the complete list. Example of linked list implementation in C based on the picture above  struct node{ int data; struct node *next; }; node *A; A = NULL; //empty list node *temp = (node*)malloc(sizeof(node)); temp->data=2; temp->next=NULL; A=temp; node *temp1 = A; while(temp1->next!=NULL) { temp1=temp1->next; temp1->next=temp; } Circular Singly Linked List  Main difference in a single linked list is that it doesn't have of NULL values in the list. The last node will link to the head node so it's circular. Doubly Linked List Every node is a data structure that contains two links, 1 line contains reference to both previous and next data/node. In code it can be written like : struct t_node{ int value; struct node* next;  struct node* prev; }; typedef struct t_node tnode; Examples of inserting new node : tnode *head=0; tnode *tail=0; tnode *node=(tn...