In computer science, a linked list is a linear collection of elements, called nodes, each node have info field and next field pointing to the next node by means of a pointer. It is a data structure consisting of a group of nodes in sequence and connected with links. In simplest form of this data structure, each node is consist of data and a reference (in other words, a link) to the next node in the sequence. This structure allows for efficient insertion or removal of elements from any position in the sequence during iteration.
Now we will see how to delete node at position 'N' in circular link list. Algorithm to delete node at position 'N' in circular link list: In this algorithm, TAIL points to last node of the link list and POS is position where the new node to be deleted. The steps are as follows: Initialize TEMP and TEMP2 If list have no node or position is less than one (TAIL == NULL or POS < 1) Node cannot be deleted Else If (POS == 1) If list have one node (TAIL->NEXT == TAIL) Delete TAIL (TAIL = NULL) Else Delete the first node (TAIL->NEXT = TAIL->NEXT->NEXT) End If; Else Set TEMP = TAIL->NEXT (TEMP now points to first node) Traverse the list for (POS-1)th node using TEMP If node to be deleted is last node i.e. (TEMP->NEXT == TAIL) Set TAIL = TEMP End If; Set TEMP->NEXT = TEMP->NEXT->NEXT End If; End If; Function to delete node at position 'N' in circular link list: int deleteAtPosition(NODE **tail, ...
Comments
Post a Comment