Posts

Showing posts from April, 2020

DATA STRUCTURE SUMMARY

Image
Linked List Like arrays, Linked List is a linear data structure. Unlike arrays, linked list elements are not stored at a contiguous location; the elements are linked using pointers. 1. SINGLE LINKED LIST To CREATE a linked list, we first need to define a node structure for the list. struct tnode {   int value;   struct tnode *next; }; struct tnode *head = 0; To INSERT a new value, first we should dynamically allocate a new node and assign the value to it and then connect it with the existing linked list. struct tnode *node = (struct tnode*) malloc(sizeof(struct tnode)); node->value = x; node->next  = head; head = node; To DELETE  a value, first we should find the location of node which store the value we want to delete, remove it, and connect the remaining linked list. There are 2 conditions, when the deleted value is on the head and not on the head. struct tnode *curr = head; // if x is in head n...