Question: Note: I am coding in C++ Here is list.cpp: #define _LIST_CPP #include list.h #include person.h #include // // In the `List` class, complete the `reorganizeList`

 Note: I am coding in C++ Here is list.cpp: #define _LIST_CPP

Note: I am coding in C++

Here is list.cpp:

#define _LIST_CPP

#include "list.h"

#include "person.h"

#include

//

// In the `List` class, complete the `reorganizeList` member function in

// `list.cpp`. The `reorganizeList` function must place all leaders at the

// front of the list followed by all non-leaders, while otherwise maintain

// the same order.

//

template

void List::reorganizeList() {

//your code here

}

template

List::List() {

this->head = NULL;

}

template

void List::insertBack(const T& ndata) {

static int ct = 0;

ListNode* node = new ListNode(ndata);

node->leader = (ct++ % 2 == 0);

if (!head) {

head = node;

} else {

ListNode *thru = head;

while (thru->next != NULL) { thru = thru->next; }

thru->next = node;

}

}

template

const T *List::get(int index) const {

ListNode *thru = head;

while (thru && index-- > 0) { thru = thru->next; }

if (thru) { return &(thru->data); }

else { return NULL; }

}

Consider a game night for students, where each student is added to a end of a linked list in the order they arrive to the game night. To help organize the games, every other student is a leader. For example: 1st rightarrow 2nd rightarrow 3rd rightarrow 4th rightarrow 5th rightarrow 6th rightarrow ... Alice rightarrow Bob rightarrow Carol rightarrow Don rightarrow Erin rightarrow Faythe rightarrow ... [Leader] [Leader] [Leader] In the List class, complete the reorganizeList member function in list-p2.cpp. The reorganizeList function must place all leaders at the front of the list followed by all non-leaders, while otherwise maintaining the same order. Using the example above, the new list must be the following: 1st rightarrow 3rd rightarrow 5th rightarrow 2nd rightarrow 4th rightarrow 6th rightarrow ... Alice rightarrow Carol rightarrow Erin rightarrow Boh rightarrow Don rightarrow Faythe rightarrow ... [Leader] [Leader] [Leader] The List class (list p2.cpp, list.h) stores a singly linked list of ListNode nodes, using the same structure and variable names as MP3. The ListNode class contains a bool leader that will be set to true when that entry contains a leader. A complete Makefile and tester code is provided for you. To compile and test, run: make ./gameNight-test

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!