Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a function expand, which takes in a pointer to the head of the linked lis

ID: 3826740 • Letter: C

Question

Create a function expand, 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 all strings repeat following the rules described above.

Example:

"apple"->NULL

return "apple"->"apple"->NULL

"green"->"green"->"blue"->"red"->"green"->NULL

return "green"->"green"->"blue"->"blue"->"red"->"red"->"green"->"green"->NULL

The linked lists for this problem use the following class declaration:

class node {

public: string data;

node* next;

};

Do this in C++. Code in bold CANNOT be changed:

node* expand(node* head) {

while(head != NULL) {

head->data = head->data+head->next;

head = head->next;

}

}

Explanation / Answer

Hi, Please find my implementation.

Please let me know in case of any issue.

class node {
public:
string data;
node* next;
};

Do this in C++. Code in bold CANNOT be changed:
node* expand(node* head) {
node *temp = head;
while(temp != NULL){
node *newNode = new node;
node->data = temp->data;
newNode->next = temp->next;
temp->next = newNode;
temp = newNode->next;
}

return head;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote