
// FILL IN THE BLANKS (LINKED-LISTS CODE) (C++)
#include<iostream>
using namespace std;
struct ________ {
int data ;
struct node *next;
};
node *head = ________;
node *createNode() { // allocate a memory
node __________;
temp = new node ;
return _______ ;
}
void insertNode(){
node *temp, *traverse;
int n;
cout<< "Enter -1 to end "<<endl;
cout<< "Enter the values to be added in list"<<endl;
cin>>n;
while(n!=-1){
temp = createNode(); // allocate memory
temp->data = ________;
temp->next = ________;
if ( ___________ == NULL){
head = _________;
}
else {
traverse = ( );
while (traverse->next != ________{
traverse = traverse-> ___________;
}
traverse->next= temp;
}
cout<<"Enter the value to be added in the list"<<endl;
cin>>n;
}
}
void printlist(){
node *traverse = head; // if head == NULL
while (traverse != NULL) {
cout<<traverse->data<<" ";
traverse = traverse->next;
}
}
int main(){
int option;
do{
cout<<"\n =============== MAIN MENU ===============”<<endl
cout << "1. Create a List " << endl;
cout << "2. Print List" << endl
cout << "Exit" << endl;
cin>> ________;
switch(option){
case 1: _______________;
break;
case 2: _______________;
break;
case 3: _______________;
}
} while (option != ________ );
}

Step by stepSolved in 2 steps

- C++ Program #include <iostream>#include <cstdlib>#include <ctime>using namespace std; int getData() { return (rand() % 100);} class Node {public: int data; Node* next;}; class LinkedList{public: LinkedList() { // constructor head = NULL; } ~LinkedList() {}; // destructor void addNode(int val); void addNodeSorted(int val); void displayWithCount(); int size(); void deleteAllNodes(); bool exists(int val);private: Node* head;}; // function to check data exist in a listbool LinkedList::exists(int val){ if (head == NULL) { return false; } else { Node* temp = head; while (temp != NULL) { if(temp->data == val){ return true; } temp = temp->next; } } return false;} // function to delete all data in a listvoid LinkedList::deleteAllNodes(){ if (head == NULL) { cout << "List is empty, No need to delete…arrow_forward#include using namespace std; struct ListNode { string data; ListNode *next; }; int main() { ListNode *p, *list; list = new ListNode; list->data = "New York"; p new ListNode; p->data = "Boston"; list->next = p; p->next = new ListNode; p->next->data = "Houston"; p->next->next = nullptr; // new code goes here Which of the following code correctly deletes the node with value "Boston" from the list when added at point of insertion indicated above? O list->next = p; delete p; O p = list->next; %3D list->next = p->next; delete p; p = list->next; list = p->next; delete p; O None of these O p = list->next; %3D list->next = p; %3D delete p;arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





