Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN C++!! CODE to be modified listed here. #include using namespace std; //structure of node typedef struct _node { int info; struct _node* next; }node;

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

IN C++!!

CODE to be modified listed here.

#include

using namespace std;

//structure of node typedef struct _node { int info; struct _node* next; }node; //LinkedList class class LinkedList { private: node* head; public: //constructor LinkedList LinkedList() { head = nullptr; } //Re-initialize void reinitialize() { head = nullptr; } //function to insert a value into a list void insert(int val) { node* newnode = new node;

newnode->info = val;

if (head == nullptr) { newnode->next = nullptr; head = newnode; return; }

node* pre, * temp = head;

if (temp->info > val) { newnode->next = head; head = newnode; return; }

while (temp != NULL && temp->info next; }

if (temp != NULL && temp->info == val) { cout

newnode->next = temp; } //function to remove a value from a list void remove(int val) { node* temp, * pre; temp = head;

if (temp->info == val) { head = temp->next; temp->next = nullptr; delete temp; return; }

while (temp != nullptr && temp->info != val) { pre = temp; temp = temp->next; } if (temp == nullptr) return; temp->next = nullptr; delete temp; } //function to check is a list empty or not void isEmpty() { if (head == nullptr) cout

while (temp != nullptr) { temp = temp->next; count++; } return count; } //function to check whether or not a particular value is present in a list void isPresent(int val) { node* temp = head;

while (temp != nullptr && temp->info != val) { temp = temp->next; }

if (temp != nullptr && temp->info == val) cout

for (int i = 1; temp != nullptr && i next; }

if (temp == nullptr) return -1; return temp->info; } //function to display the list void print() { node* temp = head;

if (temp == nullptr) { cout info; temp = temp->next;

while (temp != nullptr) { cout info; temp = temp->next; } cout "

menu();

//while loop while (1) { cout "; cin >> n;

//switch command switch (n) { case 'e': list.reinitialize(); cout > val; list.insert(val); break; case 'r': cin >> val; list.remove(val); break; case 'm': list.isEmpty(); break; case 'l': val = list.length(); cout > val; list.isPresent(val); break; case 'k': cin >> k; val = list.find(k); if (val == -1) cout

return 0; }

TITLE IMPLEMENTING A LINKED LIST WITH RECURSIVE FUNCTIONS INTRODUCTION The linked list operations implemented in Project 3 that involved iteration (loops) can also be implemented recursively. This project modifies the previous one by carrying out those operations using recursion. DESCRIPTION Modify the List class in Project 3 to carry out repetitive operations recursively. These operations include: Dispose of the dynamic part of a List structure (the destructor). Re-initialize an existing List to be empty. Insert a value into a List in the appropriate position. If the value is already present, the List is unchanged. Remove a value from a List. If the value is not present the List is unchanged. Return the length of a List. Report whether or not a particular value is present in a List. Return the value of the kth element of a List. Write out the values in a List, in order to an output stream. The remaining operations are unchanged. The client program is also unchanged: only the List class is modified. INPUT The program reads commands to manipulate its List. These commands consist of a letter followed perhaps by one integer. For example, the command "i 25" might tell the program to insert the value 25 into the List. OUTPUT The program writes to the terminal instructions and a menu of commands, and it prompts for the user's input. ERRORS The program may assume that the input the user provides is correct; except that it will report if a position is beyond the end of a list (See the example below). Otherwise, it need not detect any errors. EXAMPLE A run of the program might look something like this: This program responds to commands the user enters to manipulate an ordered list of integers, which is initially empty. In the following commands, v is any integer, and p is a position in the list. Re-initialize the list to be empty. i v Insert the value v into the list. Remove the value v from the list. 1 Report the length of the list. pv-- Is the value v present in the list? kn Report the nth value of the list. Write out the list. h See this menu. Quit. e -- r V 9 --> i 27 --> i 42 --> i 15 --> i 33 --> i 14 --> W List: -->r 33 --> W List: --> p 22 The value 22 is NOT present in the list. --> p 42 The value 42 is present in the list. --> k 3 The 3th element of the list is 27. --> k 9 The list does not contain 9 values. --> 9 OTHER REQUIREMENTS Use a typedef statement to specify the item type in the class's lists, so that this type can be changed easily. Represent the elements of a list in a linked list. Maintain a list's elements in order in its linked list; this is part of the invariant of the implementation. To write out a list, overwrite the inserter operator

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases 28th British National Conference On Databases Bncod 28 Manchester Uk July 2011 Revised Selected Papers Lncs 7051

Authors: Alvaro A.A. Fernandes ,Alasdair J.G. Gray ,Khalid Belhajjame

2011th Edition

3642245765, 978-3642245763

More Books

Students also viewed these Databases questions

Question

6. Conclude with the same strength as in the introduction

Answered: 1 week ago

Question

7. Prepare an effective outline

Answered: 1 week ago