recursion - c++ calling a recursive function that returns an object -
i'm writing .cpp file linked list class, , helper function insert returns pointer node. here i've written far:
void linkedlist::insert(course* newcourse) { course *temp = newcourse; temp = insertafter(head_ptr, newcourse); } //insert's helper function course linkedlist::*insertafter(course *current_ptr, course *newcourse) { if (current_ptr == nullptr) { current_ptr = newcourse; return nullptr; } else if (newcourse->coursenumber < current_ptr->next->coursenumber) { newcourse->next = current_ptr->next; current_ptr = newcourse; return nullptr; } else return insertafter(current_ptr->next, newcourse); }
i have 2 questions, how call helper function, , suppose return after hit end of list, , after insert node
Comments
Post a Comment