Answer any one of these questions, thank you! Objective: The objective of this d
ID: 3704654 • Letter: A
Question
Answer any one of these questions, thank you! Objective: The objective of this discussion is to study circular linked lists and doubly linked lists. Feel free to answer only one question among the following ones. 1. If you were going to implement the FIFO Queue ADT as a circular linked list, with the external pointer accessing the "rear" node of the queue, which member functions would you need to change? list, would you have to change the class definition? If so, how? Sorted List ADT as a doubly linked list. 2. If you were to rewrite the implementation of the Sorted List ADT using a doubly linked be necessary to implement the
Explanation / Answer
Ques 2.
We would have to change the class definition which defines the node. As now we are using a doubly linked list, so now the list contains
class Node
{
int data;
Node *next;
Node *prev;
public:
// constructor
Node()
{
this->data = 0;
this->next = NULL;
this->prev = NULL;
}
// constructor
Node(int data, Node *next, Node *prev)
{
this->data = data;
this->next = next;
this->prev = prev;
}
// setter methods
void setData(int data)
{
this->data = data;
}
void setNext(Node *next)
{
this->next = next;
}
void setPrev(Node *prev)
{
this->prev = prev;
}
// getter methods
int getData()
{
return this->data;
}
Node* getNext()
{
return this->next;
}
Node* getPrev()
{
return this->prev;
}
}
Also, we need to add a pointer head which points to the head of the list in the DoublyLinkedList class.
class DoubleLinkedList
{
Node *head;
// other methods are defined here
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.