



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




8, 11, -1, 14, 89, 27, 8, 11, 34, 17, 8, 17 -1, 12, 27, 8, 34, 17, 55, 45, 8, 17
Then the resulting vector should contain the values
-1, 8, 17, 27, 34
Much less credit will be given for a O(N 2 ) solution, where N is the length of the vectors, but give such a solution if it is the only one you can think of. You may specify the function prototype however you wish.
template
In Lab 10 you implemented the stack using a std::vector. In this question you are not allowed to use either a std::vector or a std::list. Instead you are to implement the stack using a dynamically-allocated array. To answer the question, show what private member vari- ables are needed and provide the implementation of the default constructor, the destructor, stack
void insert_in_order( double x, queue
You may only use the public queue interface (member functions) as specified in lab. You may use a second queue as local variable scratch space or you may try to do it in a single queue (which is a bit harder). Give an “O” estimate of the number of operations required by this function.
The characters can only be replaced one character at a time — they cannot be rearranged. Furthermore, each word must appear in the provided dictionary and words cannot be repeated in the ladder.
(a) First, write a function next word that enumerates all possible words that can be adjacent to an input word, current. The function takes a second parameter, dictionary, which is simply the set of all valid words that may appear in a word ladder. The function returns a vector of the possible next words. Here is the prototype for your function: vector
unsigned int test3_hash( const string& key, int N ) { unsigned int value = 1; for ( int i=0; i<key.size(); i += 2 ) value = value + (key[i]*13); return value % N; }
otto hannah able was I ere I saw elba
If any one of them was stored on a stack of chars your function should return true. The problem with using a stack is that it can not be “scanned” forward and backward (e.g. using iterators) in the sense that a vector or a list may be scanned. The only container classes your function may use are other stacks, and only the public interface of the stack class may be used:
template
You may assume that an operator== is defined for objects of type T. To receive full credit your solution must run in time O(N ), where N is the number of items on the stack. Your function prototype must be
template
template <class KeyType, class HashFunc> class hash_set { private: std::vector< std::list
The iterator class inside the hash_set class starts with
class iterator { public: friend class hash_set; // allows access to private variables private: hash_set* m_hs; // pointer to the hash_set object int m_index; // which entry in m_table int m_loc; // which location in m_table[m_index];
(a) The iterator class includes the following operator: iterator & operator--( ) { this->prev(); return *this; } Write the iterator class member function prev which this operator depends on. You may write it as though it is implemented inside the class declaration (and therefore you need not specify class scope in your function declaration).
public: // Return true if the value was not already there and was inserted bool insert( KeyType const& value );
// Return true if the value was there and was removed // Set status of value’s location to ERASED bool erase( KeyType const& value );
// Return true if the value is in the hash set. bool find( KeyType const& value ) const; };
Implement the insert, erase and find functions. Do not worry about the possibility of resizing the table, even though that would be important in practice.