Question
This problem has you modify a linked lists composed of node objects chained together via node pointers. Each node has a next pointer which points
This problem has you modify a linked lists composed of node objects chained together via node pointers. Each node has a next pointer which points to the next node in the chain. The last node is identified by having a NULL next pointer.
The linked lists for this lab store string data. Some of the strings in the linked lists repeat, and we'd like to eliminate this repetition. Specifically, if a string repeats, we want to eliminate the duplicates so that the resulting linked list only has one copy of a string in a row. (The string can repeat later in the linked list, as long as some other string occurs in between.)
Create a function compress, which takes in a pointer to the head of the linked list, and returns a pointer to the head of a linked list in which repetition has been eliminated.
The linked list for this problem uses the following class declaration:
class node { public: string data; node* next; };
Examples
"apple"->NULL
return "apple"->NULL
"apple"->"apple"->NULL return "apple"->NULL
"green"->"green"->"blue"->"red"->"green"->NULL return "green"->"blue"->"red"->"green"->NULL
WRITE THE FUNCTION AS
node* compress(node* head) {
}
Note: language is c++
Step 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