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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!