Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A self adjusting linked list is a linked list where a successful search causes the list to adjust so that the found item is moved

A self adjusting linked list is a linked list where a successful search causes the list to adjust so that the found item is moved to the front (and thus allowing successive search for same item to be more readily found).

Given the following class declarations for a singly linked self adjusting linked list:

template  clsss SelfAdjustingList{ struct Node{ T value_; Node* next_; Node(const T& data=T{},Node* next=nullptr){...} }; Node* front_; Node* back_; public: class const_iterator{ friend class SelfAdjustingList; Node* curr_; const_iterator(Node* n){...} public: const_iterator(){...} const_iterator operator++(){...} const_iterator operator++(int){...} const_iterator operator--(){...} const_iterator operator--(int){...} bool operator==(const_iterator rhs){...} bool operator!=(const_iterator rhs){...} const T& operator*()const{...} }; class iterator:public const_iterator{ friend class SelfAdjustingList; iterator(Node* n):const_iterator(n){...} public: iterator(); iterator operator++(){...} iterator operator++(int){...} iterator operator--(){...} iterator operator--(int){...} T& operator*(){...} const T& operator*()const{...} };  iterator begin(){...} iterator end(){...}  const_iterator begin() const{...} const_iterator end() const{...} };

Write the following member function:

iterator SelfAdjustingList::search(const T& v);
  • This function searches for v within the list and returns an iterator to the node where v is found. If not found, function returns end()
  • The list will be adjusted so that the found node is moved so that it becomes the first data node in the list
  • You can make use of any function you see in the declaration above. Any other function you wish to use must be written
  • Function must have run time of O(n)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Temple Of Django Database Performance

Authors: Andrew Brookins

1st Edition

1734303700, 978-1734303704

More Books

Students also viewed these Databases questions

Question

How can an organization operate without boundaries?

Answered: 1 week ago