Question: This is a c++ recursive selection sort with linked list question. I am unsure if my concept is wrong or if I messed up the

This is a c++ recursive selection sort with linked list question. I am unsure if my concept is wrong or if I messed up the steps but below is a snip of my current code (Follows generic linked list class with node and list). I just need assistance in seeing if my logic is correct and where I need changing. I understand the basics of selection sort but unsure if my recursion is messing up the order.

getNext() gets the next item (part of node class)

getItem() gets the current targeted item (part of node class)

template void LinkedList::swap_(Node** headRef, Node* currA, Node* currB, Node* previous) { *headRef = currB; currA = previous->getNext(); Node* temp = currB->getNext(); temp = currA->getNext();

}

template Node* LinkedList::recursiveSelectionSort(Node* current_first_ptr) { if (current_first_ptr == nullptr) //If only 1 return current_first_ptr;

Node* min = current_first_ptr; Node* beforeMin = nullptr; Node* ptr_;

for (ptr_ = current_first_ptr; ptr_->getNext() != nullptr; ptr_ = ptr_->getNext()) //loop through { if (ptr_->getNext()->getItem() getItem()) { min = ptr_->getNext(); beforeMin = ptr_; } }

if (min != current_first_ptr) swap_(¤t_first_ptr, current_first_ptr, min, beforeMin);

//current_first_ptr->getNext() = recursiveSelectionSort(current_first_ptr->getNext());

Node* dummy; dummy = current_first_ptr->getNext(); dummy = recursiveSelectionSort(dummy); //recursiveSelectionSort(current_first_ptr->getNext()) = current_first_ptr->getNext(); return current_first_ptr; }

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 Programming Questions!