solve part 2 ONLYYY
add output pic as well
the figure 4.1 is added already
that's the only figure we can use to solve the problem
1. Assume a list has the following element: (2, 23, 15, 5, 9) Write a series of C++ statements using the List ADT of Figure 4.1 in eBook to delete the element with value 15. 2. Using the list ADT of Figure 4.1, write a function to interchange the first two elements in the right partition of a list. 102 Chap 4 Lists, Stacks, and Queues template
class List { // List ADT private: void operator = (const List) // Protect assignment List (const List&) {} // Protect copy constructor public: List() () virtual "List() { // Default constructor // Base destructor // Reinitialize the list. The client is responsible for // reclaiming the storage used by the list elements. virtual void clear() = 0; // Insert an element at the front of the right partition // Return true if the insert was successful, false otherwise virtual bool insert (const Elem.) = 0; // Append an element at the end of the right partition // Return true if the append was successful, false otherwise virtual bool append (const Elem.) 0; 1/ Remove and return the first element of right partition. virtual Elem remove() = 0; // Place fence at list start, making left partition empty. virtual void movetoStart() = 0; // Place fence at list end, making right partition empty. virtual void movetoEnd() = 0; // Move fence one step left; no change if at beginning. virtual void prev () = 0; 17 Move fence one step right; no change it already at end. virtual void next() = 0; // Return length of left or right partition, respectively. virtual int leftLength() const = 0; virtual int right Length() const = 0; // Set fence so that left partition has "pos" element virtual void movetoPos (int pos) = 0; // Return the first element of the right partition. virtual const Elem getValue() const - 0; Figure 4.1 The C++ abstract class declaration for a list. 102 Chap 4 Lists Stacks, and Queues template class List { // List ADT private: void operator = (const List&) 0 1 / Protect assignment List (const Lists) () 1/ Protect copy constructor public: List() // Default constructor virtual "List() () // Base destructor // Reinitialize the list. The client is responsible for // reclaiming the storage used by the list elements. virtual void clear() = 0; // Insert an element at the front of the right partition // Return true if the insert was successful, false otherwise. virtual bool insert (const Elem&) = 0; // Append an element at the end of the right partition. // Return true if the append was successful, false otherwise. virtual bool append (const Elem&) - 0; // Remove and return the first element of right partition. virtual Elem remove() = 0; // Place fence at list start, making left partition empty. virtual void movetoStart() = 0; // Place fence at list end, making right partition empty. virtual void movetoEnd() = 0; // Move fence one step left; no change if at beginning virtual void prev () = 0; // Move fence one step right; no change if already at end. virtual void next() = 0; // Return length of left or right partition, respectively. virtual int left Length() const = 0; virtual int right Length() const = 0; // Set fence so that left partition has "pos" elements. virtual void movetoPos (int pos) = 0; // Return the first element of the right partition. virtual const Elem getValue() const = 0; Figure 4.1 The C++ abstract class declaration for a list. 1. Assume a list has the following element: (2, 23, 15, 5, 9) Write a series of C++ statements using the List ADT of Figure 4.1 in eBook to delete the element with value 15. 2. Using the list ADT of Figure 4.1, write a function to interchange the first two elements in the right partition of a list. 102 Chap 4 Lists, Stacks, and Queues template class List { // List ADT private: void operator = (const List) // Protect assignment List (const List&) {} // Protect copy constructor public: List() () virtual "List() { // Default constructor // Base destructor // Reinitialize the list. The client is responsible for // reclaiming the storage used by the list elements. virtual void clear() = 0; // Insert an element at the front of the right partition // Return true if the insert was successful, false otherwise virtual bool insert (const Elem.) = 0; // Append an element at the end of the right partition // Return true if the append was successful, false otherwise virtual bool append (const Elem.) 0; 1/ Remove and return the first element of right partition. virtual Elem remove() = 0; // Place fence at list start, making left partition empty. virtual void movetoStart() = 0; // Place fence at list end, making right partition empty. virtual void movetoEnd() = 0; // Move fence one step left; no change if at beginning. virtual void prev () = 0; 17 Move fence one step right; no change it already at end. virtual void next() = 0; // Return length of left or right partition, respectively. virtual int leftLength() const = 0; virtual int right Length() const = 0; // Set fence so that left partition has "pos" element virtual void movetoPos (int pos) = 0; // Return the first element of the right partition. virtual const Elem getValue() const - 0; Figure 4.1 The C++ abstract class declaration for a list. 102 Chap 4 Lists Stacks, and Queues template class List { // List ADT private: void operator = (const List&) 0 1 / Protect assignment List (const Lists) () 1/ Protect copy constructor public: List() // Default constructor virtual "List() () // Base destructor // Reinitialize the list. The client is responsible for // reclaiming the storage used by the list elements. virtual void clear() = 0; // Insert an element at the front of the right partition // Return true if the insert was successful, false otherwise. virtual bool insert (const Elem&) = 0; // Append an element at the end of the right partition. // Return true if the append was successful, false otherwise. virtual bool append (const Elem&) - 0; // Remove and return the first element of right partition. virtual Elem remove() = 0; // Place fence at list start, making left partition empty. virtual void movetoStart() = 0; // Place fence at list end, making right partition empty. virtual void movetoEnd() = 0; // Move fence one step left; no change if at beginning virtual void prev () = 0; // Move fence one step right; no change if already at end. virtual void next() = 0; // Return length of left or right partition, respectively. virtual int left Length() const = 0; virtual int right Length() const = 0; // Set fence so that left partition has "pos" elements. virtual void movetoPos (int pos) = 0; // Return the first element of the right partition. virtual const Elem getValue() const = 0; Figure 4.1 The C++ abstract class declaration for a list