Bubble Sort Get link Facebook X Pinterest Email Other Apps September 04, 2022 Bubble Sort: Compare two consecutive elements. Swap if they are out of order. Highest number will bubble to end after each pass. Get link Facebook X Pinterest Email Other Apps Comments
Link List September 20, 2025 #include "bits/stdc++.h" using namespace std; class Node { public: int data; Node *next; Node(int d) : data(d), next(NULL) {} }; class LinkedList { private: Node *head; public: LinkedList() : head(nullptr) {} ~LinkedList() { Node *curr = head; while(curr != NULL) { Node *nextNode = curr->next; delete curr; curr = nextNode; } } void insertAtHead(int data) { Node *tempNode = new Node(data); tempNode->next = head; head = tempNode; } void printList() { Node *currNode = head; if (currNode == nullptr) { cout data "; currNode = currNode->next; } cout data == key) { Node *tempNode = head; head = head->next; delete tempNode; return; } // 3. Delete last node Node *curr = head; Node *prev = nu... Read more
Comments
Post a Comment