to be included in a template unsorted list class, called searchAndPromote, that
ID: 3733986 • Letter: T
Question
to be included in a template unsorted list class, called searchAndPromote, that wi n item parameter. If the item is not found, the function will return false. If the item is item hunction will return true AND will move the item to the beginning of the list (do not modify the e, if the list is: 37 12 4 45 8 66 2 and the item is 8, the method will move 8 to the empty, print an appropriate message and return false. the Nst for of the elements in the list) o ening and the list becomes: 8 3 7 12 4 45 66 2 if a list isExplanation / Answer
// assuming List has member variables arr and size template bool List::searchAndPromote(T value) { if(size == 0) { // if list is empty, return false return false; } else { int index = -1; for(int i = 0; i 0; i--) { // shift all elements until found index arr[i] = arr[i-1]; } arr[0] = value; // set first element to value return true; } } }Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.