Implement a data structure BucketArray. The implementation must be a class template. It must have the following features: stores representatives of class Pair. A pair is composed by two objects of any...

1 answer below »

Implement a data structure BucketArray. The implementation must be a class template. It must have the following features:



  • stores representatives of class Pair. A pair is composed by two objects of any data type

  • each cell of the bucket array can store a whole collection of pairs. The collection is managed as a linked list of pairs

  • the capacity of the BucketArray is dynamic. It can grow, it can shrink during the execution of the program

  • the bucket array has an iterator that can visit all entries stored in the data structure. Print them out one after another

(MUST BE WRITTEN USING LINUX TEXT EDITOR)
Answered Same DayJan 29, 2021

Answer To: Implement a data structure BucketArray. The implementation must be a class template. It must have...

Swapnil answered on Jan 29 2021
155 Votes
#include
using namespace std;
struct Node
{
    int data;
    Node *next, *prev;
    public:
    Node(int val)
    {
        data = val;
        next=nullptr;
        prev=nullptr;
    }
    friend class Deque;
};
class Deque
{
    Node *front;
    Node *rear;
    public:
    Deque();
    Deque(Deque ©);
    ~Deque();
    void operator = (Deque ©);
    void insertFront(int val);
    void insertBack(int val);
    int removeFront();
    int removeBack();
    int peekFront();
    int peekBack();
    bool empty();
    int size();
};
Deque::Deque()
{
    front=nullptr;
    rear=nullptr;
}
Deque::Deque(Deque ©)
{
    Node* curr=copy.front;
    if(curr==nullptr)
    return;
    front = new Node(curr->data);
    Node *temp = front;
    while(curr->next!=nullptr)
    {
        temp->next = new Node(curr->next->data);
        temp->next->prev = temp;
        curr = curr->next;
        temp = temp->next;
    }
    rear = temp;
}
Deque::~Deque()
{
    Node *temp=front;
    front=nullptr;
    Node *temp2;
    while(temp!=nullptr)
    {
        temp2=temp;
        temp=temp->next;
        delete(temp2);
    }
    rear = nullptr;
}
void Deque::operator=(Deque...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here