Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mobile Communications

Authors: Jochen Schiller

2nd edition

978-0321123817, 321123816, 978-8131724262

More Books

Students also viewed these Programming questions

Question

c. What is the persons contact information?

Answered: 1 week ago