Question: I just need help with Searching.h please do not change the code Searching.h #ifndef SEARCHING_H_ #define SEARCHING_H_ #include Vector.h #include List.h using namespace std; template
I just need help with Searching.h please do not change the code
Searching.h
#ifndef SEARCHING_H_ #define SEARCHING_H_
#include "Vector.h" #include "List.h" using namespace std;
template // LINEAR SEARCH OF VECTOR // return index at which target found, if not found return -1; template // LINEAR SEARCH OF LINKED LIST // return iterator to node at which target // found in lst; else return iterator at end() of lst; template // BINARY SEARCH OF VECTOR; // returns index at which target found, else -1; template // BINARY SEARCH OF LINKED LIST // returns iterator at target value found; iterator end() else; template // HW: Implement this function; } #endif List.h #ifndef LIST_H #define LIST_H using namespace std; template Node( const T & d = T{ }, Node * p = nullptr, Node * n = nullptr ) : data{ d }, prev{ p }, next{ n } { } Node( T && d, Node * p = nullptr, Node * n = nullptr ) : data{ std::move( d ) }, prev{ p }, next{ n } { } }; public: class const_iterator { public: // Public constructor for const_iterator. const_iterator( ) : current{ nullptr } { } const T & operator* ( ) const { return retrieve( ); } const_iterator & operator++ ( ) { current = current->next; return *this; } const_iterator operator++ ( int ) { const_iterator old = *this; ++( *this ); return old; } const_iterator & operator-- ( ) { current = current->prev; return *this; } const_iterator operator-- ( int ) { const_iterator old = *this; --( *this ); return old; } bool operator== ( const const_iterator & rhs ) const { return current == rhs.current; } bool operator!= ( const const_iterator & rhs ) const { return !( *this == rhs ); } // iterators side-by-side bool operator > (const const_iterator & rhs) const { return current->prev == rhs.current; } protected: Node *current; T & retrieve( ) const { return current->data; } const_iterator( Node *p ) : current{ p } { } friend class List class iterator : public const_iterator { public: iterator( ) { } T & operator* ( ) { return const_iterator::retrieve( ); } const T & operator* ( ) const { return const_iterator::operator*( ); } iterator & operator++ ( ) { this->current = this->current->next; return *this; } iterator operator++ ( int ) { iterator old = *this; ++( *this ); return old; } iterator & operator-- ( ) { this->current = this->current->prev; return *this; } iterator operator-- ( int ) { iterator old = *this; --( *this ); return old; } protected: iterator( Node *p ) : const_iterator{ p } { } friend class List public: List( ) { init( ); } ~List( ) { clear( ); delete head; delete tail; } List( const List & rhs ) { init( ); for( auto & x : rhs ) push_back( x ); } List & operator= ( const List & rhs ) { List copy = rhs; std::swap( *this, copy ); return *this; } // keep for compiler List(List&& rhs) : theSize{ rhs.theSize }, head{ rhs.head }, tail{ rhs.tail } { rhs.theSize = 0; rhs.head = nullptr; rhs.tail = nullptr; } // keep for compiler List& operator= (List&& rhs) { std::swap(theSize, rhs.theSize); std::swap(head, rhs.head); std::swap(tail, rhs.tail); return *this; } iterator begin( ) { return iterator( head->next ); } const_iterator begin( ) const { return const_iterator( head->next ); } iterator end( ) { return iterator( tail ); } const_iterator end( ) const { return const_iterator( tail ); } // Return number of elements currently in the list. int size( ) const { return theSize; } // Return true if the list is empty, false otherwise. bool empty( ) const { return size( ) == 0; } void clear( ) { while( !empty( ) ) pop_front( ); } T & front( ) { return *begin( ); } const T & front( ) const { return *begin( ); } T & back( ) { return *--end( ); } const T & back( ) const { return *--end( ); } void push_front( const T & x ) { insert( begin( ), x ); } void push_back( const T & x ) { insert( end( ), x ); } void pop_front( ) { erase( begin( ) ); } void pop_back( ) { erase( --end( ) ); } // Insert x before itr. iterator insert( iterator itr, const T & x ) { Node *p = itr.current; ++theSize; return iterator( p->prev = p->prev->next = new Node{ x, p->prev, p } ); } // Erase item at itr. iterator erase( iterator itr ) { Node *p = itr.current; iterator retVal( p->next ); p->prev->next = p->next; p->next->prev = p->prev; delete p; --theSize; return retVal; } iterator erase( iterator from, iterator to ) { for( iterator itr = from; itr != to; ) itr = erase( itr ); return to; } private: int theSize; Node *head; Node *tail; void init( ) { theSize = 0; head = new Node; tail = new Node; head->next = tail; tail->prev = head; } }; #endif Main.cpp 

Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
