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

using two temporary linked list iterators and three for-loops to modify a linked

ID: 3584137 • Letter: U

Question

using two temporary linked list iterators and three for-loops to modify a linked list with a perfectShuffle (): function (only modify the TODO line of code).. Here is the driver code: #include #include #include "linkedList.h" using namespace std; template void printList(linkedListType& list); template void perfectShuffle(linkedListType& list); int main(int argc, char **argv) { // Declare list variables linkedListType list; // Add some data to list 1 list.insertLast(121); list.insertLast(3); list.insertLast(541); list.insertLast(108); list.insertLast(634); list.insertLast(171); list.insertLast(189); list.insertLast(311); list.insertLast(234); list.insertLast(876); // Print out the lists cout << " List: "; printList(list); cout << endl; perfectShuffle(list); cout << " Perfect Shuffled: "; printList(list); cout << " ** Press any key to continue ** "; getchar(); cin.ignore(256, ' '); cout << "Press ENTER to continue..." << endl; cin.get(); return 0; } template void printList(linkedListType& list) { for (linkedListIterator itr = list.begin(); itr != list.end(); ++itr) { cout << *itr << " "; } return; } template void perfectShuffle(linkedListType& list) { // TODO: implement the details for a perfect shuffle return; } Use a for-loop to find the middle element in the list (e.g. list.length()/2) and insert it into the top half temporary list. Then delete if from the main list. Use another for-loop to divide the main list into two lists by inserting the elements into the two temporary lists. Use a third for-loop to merge the lists. Output: The output of the program after both functions are implemented will be: List: 121 3 541 108 634 171 189 311 234 876 Perfect Shuffled: 171 634 121 189 3 311 541 234 108 876 ** Press any key to continue **

Explanation / Answer

some_iterator = some_vector.begin(); while (some_iterator != some_vector.end()) { if (/* some condition */) { some_iterator = some_vector.erase(some_iterator); // some_iterator now positioned at the element after the deleted element } else { if (/* some other condition */) { some_iterator = some_vector.insert(some_iterator, some_new_value); // some_iterator now positioned at new element } ++some_iterator; } }