Question
lab6code.cpp #include #include #include using namespace std; struct Node { char data[201]; Node *next; Node(char *value, Node *n = NULL) { strcpy(data, value); next =
lab6code.cpp
#include
using namespace std;
struct Node { char data[201]; Node *next; Node(char *value, Node *n = NULL) { strcpy(data, value); next = n ; } };
void addToList(Node** head, char *d) { Node* temp = new Node(d, NULL); Node *last = *head; if (*head == NULL) { *head = temp; return; } while (last->next != NULL) last = last->next; last->next = temp; return; }
void printList(Node *node) { if(node == NULL){ coutdata next;
} cout
int main() {
Node* head = NULL; cout
return 0; }
Can use the code provided from lab6 to rewrite the printList function and add the new function,
or can write a whole new program to meet the requirements.
First, rewrite the printList function from lab 6 to be completely recursive. To do this, start by looking at the while loop and thinking about what would be a good base case (the stopping point for the function) and what needs to happen when not at the base case yet. Second, write a new functio(isWordlnList) that searches the list for a given word. If it finds it, it should print "word found". If it doesn't find it, it should print "word NOT found". This should be done recursively also. HINT: There are two base cases here: when the word is found and when we reach the end of the list. Remember to take care of both before recursing further. Call isWordlnList after all the words have been added to the list. Ask for the word to search on outside of isWordlnList and pass this into the first call to this function. Requirements You should not have any while loops in the printList or isWordlnList functions. You can have them in other functions including main. The printList should work as before printing all the nodes in the listStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started