Consider the following implementation of the node and doubly linked-list: template class node { public: type info; node * next;// next node * prev;//back }; template class doubly_linked_list { //data members private: node *head, *tail; int length; public: doubly_linked_list() { head = tail = NULL; length = 0; } bool isEmpty() { // return (head==NULL); if (head == NULL) return true; else return false; } void Append(type e) { node *newnode = new node; newnode->info = e; if (isEmpty()) { newnode->next = NULL; newnode->prev = NULL; head = newnode; tail = newnode; } else { tail->next = newnode; newnode->prev = tail; newnode->next = NULL; tail = newnode; } ++length; } void Display() { if (isEmpty()) { cout << "The linked list is empty !!!!"; return; } cout << "list elements: "; node * current = head; while (current != NULL) { cout << current->info << " "; current = current->next; } cout << endl; } void ReverseDisplay() { if (isEmpty()) { cout << "The linked list is empty !!!!"; return; } cout << "Reverse list elements: "; node * current = tail; while (current != NULL) { cout<< current->info<<" "; current = current->prev; } cout << endl; } void insert(type e, int index) { if (index< 1 || index>length + 1) { cout << "Invalid index !!!!"; return; } else { node * newnode = new node ; newnode->info = e; if (index == 1) { newnode->prev = NULL; if (isEmpty()) { newnode->next = NULL; head = tail = newnode; } else { newnode->next = head; head->prev = newnode; head = newnode; }   } else { node * current = head; int i = 1; while (i != index - 1) { current = current->next; ++i; } if(current !=tail) { current->next->prev = newnode; newnode->next = current->next; current->next = newnode; newnode->prev = current; } else { current->next = newnode; newnode->prev = current; newnode->next = NULL; tail = newnode; } }     } } }; Extend the class doubly_linked_list by adding the following methods: Largest method .This method should return the largest element in a doubly linked-list.  Delete method. This method should delete the first occurrence of an element (value)  from a doubly linked-list.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter17: Linked Lists
Section: Chapter Questions
Problem 10PE
icon
Related questions
icon
Concept explainers
Question
100%

Consider the following implementation of the node and doubly linked-list:


template <class type>
class node
{
public:
type info;

node<type> * next;// next
node<type> * prev;//back

};


template <class type>
class doubly_linked_list
{

//data members
private:
node<type> *head, *tail;

int length;
public:
doubly_linked_list()
{

head = tail = NULL;
length = 0;
}
bool isEmpty()
{ // return (head==NULL);
if (head == NULL)
return true;
else

return false;
}


void Append(type e)
{

node<type> *newnode = new node<type>;
newnode->info = e;
if (isEmpty())
{

newnode->next = NULL;
newnode->prev = NULL;

head = newnode;
tail = newnode;

}
else

{
tail->next = newnode;

newnode->prev = tail;
newnode->next = NULL;

tail = newnode;
}

++length;

}


void Display()
{
if (isEmpty()) { cout << "The linked list is empty !!!!"; return; }

cout << "list elements: ";
node<type> * current = head;
while (current != NULL)
{
cout << current->info << " ";

current = current->next;
}
cout << endl;

}

void ReverseDisplay()

{
if (isEmpty()) { cout << "The linked list is empty !!!!"; return; }
cout << "Reverse list elements: ";

node<type> * current = tail;
while (current != NULL)
{

cout<< current->info<<" ";
current = current->prev;
}

cout << endl;
}

void insert(type e, int index)
{

if (index< 1 || index>length + 1)

{
cout << "Invalid index !!!!"; return;

}
else
{

node<type> * newnode = new node <type>;
newnode->info = e;

if (index == 1)
{
newnode->prev = NULL;

if (isEmpty())
{

newnode->next = NULL;

head = tail = newnode;
}

else {
newnode->next = head;
head->prev = newnode;
head = newnode;

}

 


}
else

{
node<type> * current = head;

int i = 1;
while (i != index - 1)

{
current = current->next;
++i;
}


if(current !=tail)

{
current->next->prev = newnode;

newnode->next = current->next;
current->next = newnode;

newnode->prev = current;

}

else
{

current->next = newnode;

newnode->prev = current;

newnode->next = NULL;
tail = newnode;

}

}

 

 


}

}

};

Extend the class doubly_linked_list by adding the following methods:

  • Largest method .This method should return the largest element in a doubly linked-list. 
  • Delete method. This method should delete the first occurrence of an element (value)  from a doubly linked-list. 
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Types of Linked List
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning