currentPtr. Use your code to make a boolean function findAndDelete that is given a pointer to a linked list and a value, and if the value is in the linked list, it is deleted and the function returns true. If it is not in the list, the function returns false. 8. Expand your menu to test your three new functions. When choosing to test the find or findAndDelete functions, the user will be first asked to enter the value to find or to find and delete. Depending on whether the functions returned true or false, the main program should write an appropriate message to the user. 9. Finally write a function called deleteList that will delete all nodes in the linked list and return the parameter head set to nullptr. You can add it to the menu for testing, but also put it at the end of the program to release all dynamic memory you used.












output


copyable code
#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
class NodeType {
public:
NodeType( int = 0 );
int info;
NodeType * nextPtr;
};
NodeType::NodeType( int data )
{
info = data;
nextPtr = 0;
}
/*
* insert_node element
*/
void insert_node(NodeType **headnode, int val)
{
NodeType *current_ptr;
current_ptr = new(NodeType);
if (current_ptr == NULL)
{
cout<<"Memory not allocated "<<endl;
return;
}
else
{
current_ptr->info = val;
current_ptr->nextPtr = *headnode;
*headnode = current_ptr;
}
cout<<"Element insert_nodeed at beginning"<<endl;
}
//delete
void deleteFirst(NodeType **headnode)
{
NodeType *tempnode = *headnode;
*headnode = tempnode->nextPtr;
delete(tempnode);
tempnode = NULL;
}
//delete list
void delete_list(NodeType **headnode)
{
NodeType *tempnode = *headnode;
while (*headnode) {
*headnode = tempnode->nextPtr;
delete(tempnode);
tempnode = *headnode;
}
}
/*
*printlist list of element
*/
void printlist(NodeType *headnode)
{
NodeType *tempnode;
if (headnode == NULL) {
cout<<"Empty List"<<endl;
return;
}
tempnode = headnode;
cout<<"lilst of elements are: "<<endl;
while (tempnode != NULL)
{
cout<<tempnode->info<<"->";
tempnode = tempnode->nextPtr;
}
cout<<"NULL"<<endl;
}
/*
* Search node
*/
bool find(NodeType *headnode, int val)
{
bool flag = false;
if (headnode == NULL) {
cout<<"empty list"<<endl;
return flag;
}
NodeType *s;
s = headnode;
while (s != NULL)
{
if (s->info == val)
{
flag = true;
cout<<"Element "<<val<<" is found"<<endl;
break;
}
s = s->nextPtr;
}
if (!flag)
cout<<"Element "<<val<<" not found in the list"<<endl;
return flag;
}
void findanddelete(NodeType **headnode, int val)
{
NodeType *prev = NULL;
NodeType *curr = *headnode;
if (find(*headnode, val)) {
while (curr) {
if ((curr == *headnode) && (curr->info == val)) {
*headnode = curr->nextPtr;
delete(curr);
cout<<"Element "<<val<<" deleted element list"<<endl;
return;
}
if (curr->info == val) {
prev->nextPtr = curr->nextPtr;
delete(curr);
cout<<"Element "<<val<<" deleted from the list"<<endl;
return;
}
prev = curr;
curr = curr->nextPtr;
}
delete(curr);
cout<<"Element "<<val<<" deleted from the list"<<endl;
return;
}
cout<<"val to deleted not found on the list"<<endl;
return;
}
int main()
{
int opt, val;
NodeType *headnode = NULL;
NodeType *current_ptr;
while (1) {
cout<<"1.Add"<<endl;
cout<<"2.printlist"<<endl;
cout<<"3.Delete First"<<endl;
cout<<"4.Find & delete"<<endl;
cout<<"5.Delete List"<<endl;
cout<<"6.Quit "<<endl;
cout<<"Enter your option : ";
cin>>opt;
switch(opt) {
case 1:
cout<<"Enter the val to be insert_nodeed: ";
cin>>val;
cout<<"insert_node at Beginning: "<<endl;
insert_node(&headnode, val);
cout<<endl;
break;
case 2:
cout<<"Display link list element"<<endl;
printlist(headnode);
cout<<endl;
break;
case 3:
cout<<"Deleting Node at the begining: "<<endl;
deleteFirst(&headnode);
cout<<endl;
break;
case 4:
cout<<"Enter the node val to deleted: "<<endl;
cin>>val;
findanddelete(&headnode, val);
break;
case 5:
cout<<"Delete list:"<<endl;
delete_list(&headnode);
cout<<endl;
break;
case 6:
cout<<"Quiting..."<<endl;
delete_list(&headnode);
exit(1);
break;
default:
cout<<"Wrong option"<<endl;
}
}
}
currentPtr. Use your code to make a boolean function findAndDelete that is given a pointer to...
In C++ syntax please
Write a program that implements and demonstrates a linked list using functions. Your program should first dehne a node that stores an integer and then your program will include the following functions appendo- This function accepts the head pointer (by reference) of a linked list and an integer as it's only arguments. It then creates a node, stores the integer argument in the node, and adds it to the end of the list. findo-This function accepts...
using C++, NOT C language 1. Write a function called insert() to insert a node to the beginning of a linked list. The data is passed into the function. For example insert(8) will insert a node at the beginning of the list with the number 8 in the data field. Each node in the linked list is a ListNode struct as discussed in class. 2. Write a function called print() that will traverse the entire linked list and print out...
C++ program, inventory.cpp implementation
Mostly need the int load(istream&) function.
Implementation: You are supposed to write three classes, called Item, Node and Inventory respectively Item is a plain data class with item id, name, price and quantity information accompanied by getters and setters Node is a plain linked list node class with Item pointer and next pointer (with getters/setters) Inventory is an inventory database class that provides basic linked list operations, delete load from file / formatted print functionalities. The...
can someone please double check my code here are the requirements please help me fulfill the requirements Using the material in the textbook (NumberList) as a sample, design your own dynamic linked list class (using pointers) to hold a series of capital letters. The class should have the following member functions: append, insert (at a specific position, return -1 if that position doesn't exist), delete (at a specific position, return -1 if that position doesn't exist), print, reverse (which rearranges...
2) (10 pts) Write a function that takes in a pointer to a linked list of nodes storing integers and a variable named value, and returns the number of nodes in the list storing that value. For example, if a list pointed to by listPtr stores 2, 6, 2, 3, 4, 2, 6, and 6 and value = 6, your function should return 3, since 6 appears in the list 3 times. Please use the struct and function prototype provided...
linked list operation
/***************************************************************************************
This function creates a new node with the information give as a parameter and looks
for the right place to insert it in order to keep the list organized
****************************************************************************************/
void insertNode(string first_name, string last_name, string phoneNumber)
{
ContactNode *newNode;
ContactNode *nodePtr;
ContactNode *previousNode = nullptr;
newNode = new ContactNode;
/***** assign new contact info to the new node here *****/
if (!head) // head points to nullptr meaning list is empty
{
head = newNode;...
Write a function, swapSubtrees, that swaps all of the left and right subtrees of a binary tree. Add this function to the class binaryTreeType and create a program to test this function. #include <iostream> using namespace std; //Definition of the Node template <class elemType> struct nodeType { elemType info; nodeType<elemType> *lLink; nodeType<elemType> *rLink; }; //Definition of the class template <class elemType> class binaryTreeType { public: //Overload the assignment operator. const binaryTreeType<elemType>& operator=(const binaryTreeType<elemType>&) { if (this != &otherTree) //avoid self-copy...
Using the provided Linked List template, add the following recursive functions and demonstrate them in a separate cpp file. Write a recursive function to print the list in order. Write a recursive function to print the list in reverse order. Write a recursive function to print every other node in the list in order. Write a recursive function to return the number of nodes in the list. Write a Boolean function that implements the recursive version of sequential search. THIS...
Using the provided Linked List example code, linkedlist.c, as an example Make a node struct that holds ints instead of strings. In your main, insert 25 to 75 random integers with range (0 to 100) into a linked list of your nodes. Use a random to determine how many to make. Write a function int sum(NodePointer current) that returns the sum of the integers in the list by looping through the linked list. Write a function int count(NodePointer current) that...