Question: #include #include #include Queue.h using namespace std; long k = 10; long f (long x){ return x % k; } int main() { // Declare

#include #include #include "Queue.h"

using namespace std;

long k = 10;

long f (long x){ return x % k; }

int main() { // Declare a vector of Queue pointers vector hashtable; // Initialize the vector with k empty Queues for (long i = 0; i < k; i++) { hashtable.push_back(new Queue()); } // This is the value I want to insert long value = 234; // Run it through the hash function to determine // to which queue we need to push it long index = f(value); // Push value to the index-th Queue hashtable[index]->push(value); // One more time value = 23; index = f(value); hashtable[index]->push(value); // One more time value = 23453; index = f(value); hashtable[index]->push(value); // Let's do some searching // This is what I am searching for value = 7; // Which queue should I be looking at index = f(value); // Look for it in the queue pointed to by index cout << hashtable[index]->find(value) << endl << endl; // Print contents of hash table for (long i = 0; i < k; i++) { Queue* current = hashtable[i]; cout << i << ": "; current->print(); cout << endl; } for (long i = 0; i < k; i++) { delete hashtable[i]; } return 0; }

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#ifndef Queue_h #define Queue_h

#include

struct Link { long data; Link* next; Link(){ data = 0; next = NULL; } Link (long d){ data = d; next = NULL; } };

struct Queue { Link* front; Link* back; Queue (){ front = NULL; back = NULL; } long peek () { return front->data; } void push(long value){ if (isEmpty()){ front = new Link(value); back = front; } else { back->next = new Link(value); back = back->next; } } bool find (long value){ // Provide your code here

} bool isEmpty(){ return (front == NULL); } long pop(){ long val = front->data; Link* oldFront = front; front = front->next; delete oldFront; return val; } void print() { // Provide your code here

} ~Queue(){ // Provide your code here

} };

#endif

the Queue struct needs 3 more functions to be implemented. A find function, which tells us it a given value appears in the queue, without being destructive. A function called print, which prints out the contents of the queue, again without being destructive. Finally, there is a need for a destructor. To implement it, you can just keep popping elements off the queue until there are no elements left.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!