Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Please!! I have include the dynamic linked list header below #ifndef DYNAMICLIST_H #define DYNAMICLIST_H #include using namespace std; class DynamicList { private: struct Node

C++ Please!!

I have include the dynamic linked list header below

#ifndef DYNAMICLIST_H #define DYNAMICLIST_H #include  using namespace std; class DynamicList { private: struct Node { int i; Node* next; }; Node* head; public: DynamicList(); ~DynamicList(); void clear(); int insert( int ); int append( int ); int remove( int ); int peek( int& ) const; bool isFull() const; bool isEmpty() const; int getLength() const; int find( int ) const; void print() const; }; DynamicList::DynamicList() { head = NULL; } DynamicList::~DynamicList() { clear(); } void DynamicList::clear() { Node* p = NULL; while( head != NULL ) { p = head; head = head->next; delete p; } } int DynamicList::insert( int i ) { if( isFull() ) return -1; Node* n = new Node; n->i = i; Node* p = head, *q = NULL; while( p != NULL && p->i next; } if( q == NULL ) { n->next = head; head = n; } else { q->next = n; n->next = p; } return 0; } int DynamicList::append( int i ) { if( isFull() ) return -1; Node* n = new Node; n->i = i; n->next = NULL; if( isEmpty() ) { head = n; return 0; } Node* p = head; while( p->next != NULL ) p = p->next; p->next = n; return 0; } int DynamicList::remove( int i ) { if ( isEmpty() ) return -1; Node* p = head, *q = NULL; while( p != NULL && p->i != i ) { q = p; p = p->next; } if( p == NULL ) return -1; if( q == NULL ) head = head->next; else q->next = p->next; delete p; return 0; } int DynamicList::peek( int& i ) const { if( isEmpty() ) return -1; i = head->i; return 0; } bool DynamicList::isFull() const { Node* dummy = new Node; if( dummy ) { delete dummy; return false; } return true; } bool DynamicList::isEmpty() const { return head == NULL; } int DynamicList::getLength() const { int len = 0; Node* p = head; while( p ) { len++; p = p->next; } return len; } int DynamicList::find( int i ) const { int pos = -1; Node* p = head; while( p ) { pos++; if( p->i == i ) return pos; p = p->next; } return -1; } void DynamicList::print() const { Node* p = head; while( p ) { cout i next; } cout  

image text in transcribed

#include "HashTable.h" #include  #include  using namespace std; int main() { HashTable h(5); h.insert("Mary"); h.insert("had"); h.insert("a"); h.insert("little"); h.insert("lamb."); h.insert("It's"); h.insert("fleece"); h.insert("was"); h.insert("white"); h.insert("as"); h.insert("snow"); h.insert("And"); h.insert("everywhere"); h.insert("that"); h.insert("Mary"); h.insert("went,"); h.insert("that"); h.insert("lamb"); h.insert("was"); h.insert("sure"); h.insert("to"); h.insert("go."); h.print(); return 0; } 
An array of dynamic linked list objects. Could re-use class Dynamic, modified for use with string obiects HashTable FTTTtable: List -size: int -hash( key string): int (query) Hash function. Converts string to hash value, an nteger +HashTable( s int) +-HashTable() +clear) void tinsert key: string ): int +remove( key string) :int +find(key string): bool +isFull(): bool (query) +isEmpty(): bool (query) print) void (query) Use the above UML diagram and descriptions below to write a class that implements a Hash table. Your implementation should use open chaining to resolve collisions. You may provide additional class attributes, as you see fit, to complete the class. The above class has the following private attributes: table: This is a pointer to the object's dynamically allocated hash table. Used to create an array of Linked List objects size stores the number of elements in the hash table (the capacity). hash the hash function. It accepts the key string and returns the hash value The class has the following public attributes: constructor accepts an integer argument used to determine the number of elements in the hash table. Dynamically allocates the hash table destructor deallocates all dynamically allocated memory insert insert's it's argument into the hash table. calls the hash function to obtain an appropriate hash address. Returns 0 if successful, -1 otherwise remove removes the first key matching it's argument from the hash table. Returns 0 if successful, -1 otherwise find returns true if a key matching it's argument is found, false otherwise clear resets the object to it's initial state isFull-returns true if the structure is full, false otherwise isEmpty-returns true if the structure has no keys, false otherwise print displays all the keys currently stored in the structure Possible sample output from the print method: Bucket e: Head->white->snow->And->went, ->go. ->NULL Bucket 1 Head->had- >was->was- >NULL Bucket 2 Head->a->fleece->as->lamb- >sure->to->NULL Bucket 3: Head->lamb. >It's->that->that- >NULL Bucket 4: Head->Mary->1little->everywhere->Mary ->NULL The above is what the 5-element hash table looks like after inserting "Mary had a little lamb. It's fleece was white as snow And everywhere that Mary went, that lamb was sure to go

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_2

Step: 3

blur-text-image_3

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

More Books

Students also viewed these Databases questions