









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A detailed overview of the implementation of linked lists, including the insertion of new nodes, deletion of existing nodes, and traversal of the list. It covers the various cases that need to be handled, such as inserting at the beginning, middle, or end of the list, as well as deleting the first node or a node in the middle or at the end. The document also includes sample code in c++ to demonstrate the implementation of these operations. Additionally, it provides references to relevant textbooks and resources for further study of data structures and algorithms.
Typology: Cheat Sheet
1 / 15
This page cannot be seen from the preview
Don't miss anything!










INSERTING A NEW NODE
th
INSERTING A NEW NODE Node* List::InsertNode(int index, double x) { if (index < 0) return NULL; int currIndex = 1; Node* currNode = head; while (currNode && index > currIndex) { currNode = currNode->next; currIndex++; } if (index > 0 && currNode == NULL) return NULL; Node* newNode = new Node; newNode->data = x; if (index == 0) { newNode->next = head; head = newNode; } else { newNode->next = currNode->next; currNode->next = newNode; } return newNode; }
INSERTING A NEW NODE Node* List::InsertNode(int index, double x) { if (index < 0) return NULL; int currIndex = 1; Node* currNode = head; while (currNode && index > currIndex) { currNode = currNode->next; currIndex++; } if (index > 0 && currNode == NULL) return NULL; Node* newNode = new Node; newNode->data = x; if (index == 0) { newNode->next = head; head = newNode; } else { newNode->next = currNode->next; currNode->next = newNode; } return newNode; }
FINDING A NODE
DELETING A NODE
DELETING A NODE int List::DeleteNode(double x) { Node prevNode = NULL; Node currNode = head; int currIndex = 1; while (currNode && currNode->data != x) { prevNode = currNode; currNode = currNode->next; currIndex++; } if (currNode) { if (prevNode) { prevNode->next = currNode->next; delete currNode; } else { head = currNode->next; delete currNode; } return currIndex; } return 0; }** prevNode currNode
DELETING A NODE int List::DeleteNode(double x) { Node prevNode = NULL; Node currNode = head; int currIndex = 1; while (currNode && currNode->data != x) { prevNode = currNode; currNode = currNode->next; currIndex++; } if (currNode) { if (prevNode) { prevNode->next = currNode->next; delete currNode; } else { head = currNode->next; delete currNode; } return currIndex; } return 0; }** head currNode
USIGN LIST
REFERENCE