Question

49. What is wrong with this definition of the List erase function? iterator List: :erase (lterat r iter) assert (iter.position !- NULL); Node* remove-iter.position; Node* beforeremove->previous; N de * after = remove->next; if (remove first) first after; last = before ; after->previousbefore; if (remove last) else delete remove; Iterator r; r.position after; r. container-this; return r; a) The before pointer should be set to the after node after the condition if (remove = first) b) The before->ext pointer should be set to the after node after the condition if (remove c The before->previous pointer should be set to the after node after the condition if d) There is no problem with the erase function. first) (remove == first)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

b. The before->next should point to after.

So that list will be continuous after erasing r from list.

Code should be:

before->next=after;

Add a comment
Know the answer?
Add Answer to:
49. What is wrong with this definition of the List erase function? iterator List: :erase (lterat...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Below is the given code of implementation: #include <string> #include <iostream> #include <list> #include <cassert> using...

    Below is the given code of implementation: #include <string> #include <iostream> #include <list> #include <cassert> using namespace std; class List; class Iterator; class Node { public: /* Constructs a node with a given data value. @param s the data to store in this node */ Node(string s); /* Destructor */ ~Node() {} private: string data; Node* previous; Node* next; friend class List; friend class Iterator; }; class List { public: /** Constructs an empty list. */ List(); /* Destructor. Deletes...

  • How to write the insert, search, and remove functions for this hash table program? I'm stuck......

    How to write the insert, search, and remove functions for this hash table program? I'm stuck... This program is written in C++ Hash Tables Hash Table Header File Copy and paste the following code into a header file named HashTable.h Please do not alter this file in any way or you may not receive credit for this lab For this lab, you will implement each of the hash table functions whose prototypes are in HashTable.h. Write these functions in a...

  • I am trying to search a name on a list and then remove it by invoking...

    I am trying to search a name on a list and then remove it by invoking the remove function. However when I search for the name it keeps on saying name not found. What am I doing wrong? (The instruction is in the comments) The remove and drop(delete) coding I have so far is below. void buddyList::remove(buddy * r) { buddy * b4 = head; if (r == head) head = head->next; else { while (b4->next != r) { b4...

  • The screenshot below states "The singly linked list STL container std::forward_list has an erase function, which...

    The screenshot below states "The singly linked list STL container std::forward_list has an erase function, which can be directly used here. But that function erases AFTER the item pointed to, not the one pointed to like the other containers. A singly linked list cannot look backwards, only forward. You need to convert the zero-based offset from the top to an iterator by advancing _groceries_sl_list.before_begin() offsetFromTop times. The STL has a function called std::next() that does that, or you can write...

  • I need this in C++. This is all one question Program 2: Linked List Class For...

    I need this in C++. This is all one question Program 2: Linked List Class For this problem, let us take the linked list we wrote in a functional manner in a previous assignment and convert it into a Linked List class. For extra practice with pointers we'll expand its functionality and make it a doubly linked list with the ability to traverse in both directions. Since the list is doubly linked, each node will have the following structure: struct...

  • linked list operation /*************************************************************************************** This function creates a new node with the information give as a...

    linked list operation /*************************************************************************************** This function creates a new node with the information give as a parameter and looks for the right place to insert it in order to keep the list organized ****************************************************************************************/ void insertNode(string first_name, string last_name, string phoneNumber) { ContactNode *newNode; ContactNode *nodePtr; ContactNode *previousNode = nullptr; newNode = new ContactNode; /***** assign new contact info to the new node here *****/ if (!head) // head points to nullptr meaning list is empty { head = newNode;...

  • Design and implement your own linked list class to hold a sorted list of integers in ascending order. The class should h...

    Design and implement your own linked list class to hold a sorted list of integers in ascending order. The class should have member function for inserting an item in the list, deleting an item from the list, and searching the list for an item. Note: the search function should return the position of the item in the list (first item at position 0) and -1 if not found. In addition, it should member functions to display the list, check if...

  • Complete P16.1 and P16.4 (Class Name: NewMethodDemo) Once complete, upload all .java files. For primary test...

    Complete P16.1 and P16.4 (Class Name: NewMethodDemo) Once complete, upload all .java files. For primary test class: Remember your header with name, date, and assignment. Also include class names that will be tested. Psuedocode (level 0 or mixture of level 0 and algorithm [do not number steps]) is required if main() contains more than simple statements (for example, your program includes constructs for decisions (if/else), loops, and methods. For Secondary class(es): Include a JavaDoc comment that describes the purpose of...

  • The source code I have is what I'm trying to fix for the assignment at the...

    The source code I have is what I'm trying to fix for the assignment at the bottom. Source code: //Group 1 - Jodie Butterworth, Brandon Kidd, Matt Heckler //11-21-19 //CSC 201 // Exercise to practice the basic manipulations of a linked list // Note: Uses nullptr, so need to make sure your compiler is set to use C++11 // In Code::Blocks this is under Settings==>Compiler #include <iostream> using namespace std; // Structure to contain data for a node (Could be...

  • Introduction In this lab, you are supposed to implement a graph class with the data structure...

    Introduction In this lab, you are supposed to implement a graph class with the data structure implemented before like linked list and queue. graph The class graph contains three member variables: linkedList *adjacentVertices; //an array of linked list. For a vertice i, adjacentVertices[i] stores the linked list that contains all other vertices connected to vertice i. int numVertices; //The number of vertices in the graph. int maxNumVertices; //The maximum number of vertices the graph can hold. Following public methods are...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT