Question
PLEASE DO NOT SPAM THE QUESTION I WILL AUTOMATICALLY DISLIKE IT (IF YOU SOLVE IT PLEASE POST A PICTURE OF IT WORKING ON YOUR END,
PLEASE DO NOT SPAM THE QUESTION I WILL AUTOMATICALLY DISLIKE IT (IF YOU SOLVE IT PLEASE POST A PICTURE OF IT WORKING ON YOUR END, THANKS)
In C++ Fix: Add a new method to the List ADT program that will search the list for a specified value and return its index in the list (or -1 if not found). Also, implement the Insert and Print methods. Please follow the comments in the code. There is a .cpp and .h file.
// File : List.h // Class: COP 3530 Digital Sys & Architecture // Dev : <
*/ void List::insert(int value, int position) { Node* temp = new Node{value, nullptr}; if (position < LIST_HEAD || position >= size) position = size; // determine where in list to insert if( size == 0 || position == LIST_HEAD) { temp->next = head; // new node points to head head = temp; // move head pointer to new node } else { // middle or tail of list // traverse list to node - 1 Node* pNode = traverse(position - 1); // insert node between current and next node temp->next = pNode->next; // new node points to next node pNode->next = temp; // current node points to new node } // where in list // increment size of the list size++; } // insert /** * Remove a value from the list at a specified position and * return it to the caller * @param position - position in the list or tail if -1 * or invalid position * @return - value removed from the list */ int List::remove(int position) { int value = -1; return value; } // remove /** * Return a value from the list at a specified position without * removing it * @param position - position in the list * @return - value found at position (-1 if not found or invalid position) */ int List::read(int position) { int value = -1; if (size > 0) { Node* pNode = traverse(position); value = pNode->value; } return value; } // read
/** * Modify a value at a specified position in the list * @param value - new value * @param position - position in the list */ void List::modify(int value, int position) { } // modify // Private methods // -------------------------------------------------------- /** * Iterate node pointer to specified position in the list * @param position - 0 to size-1 * @return pointer to Node at List[position] (or null if empty) */ List::Node* List::traverse(int position) { Node* pNode = head; // start at head of list (null if empty) int counter = 0; // zero indexed list // (don't move if position == 0) while(counter < position && pNode->next) { pNode = pNode->next; counter++; } // traversal return pNode;
// File : List.h // Class: COP 3530 Digital Sys & Architecture // Dev : <
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started