In the class we extensively discussed a node class called In

In the class we extensively discussed a node class called IntNode in which each linked list node contains an integer and each node is linked forward to the next element in the list. Implement a node class called DoublyIntNode in which each node contains an integer number and each node is linked not only forward to the next element in the list but also backward to the previous element in the list. Your implementation of DoublyIntNode should adapt and implement all the methods of IntNode including the following methods:

Constructor for DoublyIntNode

addNodeAfter, removeNodeAfter

getData, setData

getForeLink, setForeLink

getBackLink, setBackLink

listCopy

listCopyWithTail

listLength

listPart

listPosition

listSearch

IntNode and Node classes:

public class IntNode{

   private int data;

   private IntNode link;

   // methods here

}

public class Node {

   private E data;

   private Node link;

   // methods here

}

Solution

program

#include<iostream>
using namespace std;
struct list
{
   struct list *prev;
   int data;
   struct list *next;
}
*node = NULL, *first = NULL, *last = NULL, *node1 = NULL, *node2 = NULL;
class Dlist
     {
   public:
       void insert_beg() {
           list *addBeg = new list;
           cout << \"Enter value for the node:\" << endl;
           cin >> addBeg->data;
           if(first == NULL) {
               addBeg->prev = NULL;
               addBeg->next = NULL;
               first = addBeg;
               last = addBeg;
               cout << \"Linked list Created!\" << endl;
           }
           else {
               addBeg->prev = NULL;
               first->prev = addBeg;
               addBeg->next = first;
               first = addBeg;
               cout << \"Data Inserted at the beginning of the Linked list!\" << endl;
           }
       }
       void insert_end() {
           list *addEnd = new list;
           cout << \"Enter value for the node:\" << endl;
           cin >> addEnd->data;
           if(first == NULL) {
               addEnd->prev = NULL;
               addEnd->next = NULL;
               first = addEnd;
               last = addEnd;
               cout << \"Linked list Created!\" << endl;
           }
           else {
               addEnd->next = NULL;
               last->next = addEnd;
               addEnd->prev = last;
               last = addEnd;
               cout << \"Data Inserted at the end of the Linked list!\" << endl;
           }
       }
       void display() {
           node = first;
           cout << \"List of data in Linked list in Ascending order!\" << endl;
           while(node != NULL) {
               cout << node->data << endl;
               node = node->next;
           }
           node = last;
           cout << \"List of data in Linked list in Descending order!\" << endl;
           while(node != NULL) {
               cout << node->data << endl;
               node = node->prev;
           }
       }
       void del()
                    {
           int count = 0, number, i;
           node = node1 = node2 = first;
           for(node = first; node != NULL; node = node->next)
           cout << \"Enter value for the node:\" << endl;
           count++;
           display();
           cout << count << \" nodes available here!\" << endl;
           cout << \"Enter the node number which you want to delete:\" << endl;
           cin >> number;
           if(number != 1)
                            {
               if(number < count && number > 0)
                                     {
                   for(i = 2; i <= number; i++)
                       node = node->next;
                   for(i = 2; i <= number-1; i++)
                       node1 = node1->next;
                   for(i = 2; i <= number+1; i++)
                       node2 = node2->next;
                   node2->prev = node1;
                   node1->next = node2;
                   node->prev = NULL;
                   node->next = NULL;
                   node = NULL;
               }
               else if(number == count)
                                 {
                   node = last;
                   last = node->prev;
                   last->next = NULL;
                   node = NULL;
               }
               else
                   cout << \"Invalid node number!\" << endl;
                    }
           else
                             {
               node = first;
               first = node->next;
               first->prev = NULL;
               node = NULL;
                 }
           cout << \"Node has been deleted successfully!\" << endl;
       }
  
};
int main()
       {
   int op = 0;
   Dlist llist = Dlist();
   while(op != 4)
           {
       cout << \"1. Insert at the beginning\ 2. Insert at the end\ 3. Delete\ 4. Display\ 5. Exit\" << endl;
       cout << \"Enter your choice:\" << endl;
       cin >> op;
       switch(op) {
           case 1:
               llist.insert_beginning();
               break;
           case 2:
               llist.insert_end();
               break;
           case 3:
               llist.del();
               break;
           case 4:
               llist.display();
               break;
           default:
               cout << \"Invalid choice!\" << endl;
       }
   }
   return 0;
}

In the class we extensively discussed a node class called IntNode in which each linked list node contains an integer and each node is linked forward to the next
In the class we extensively discussed a node class called IntNode in which each linked list node contains an integer and each node is linked forward to the next
In the class we extensively discussed a node class called IntNode in which each linked list node contains an integer and each node is linked forward to the next
In the class we extensively discussed a node class called IntNode in which each linked list node contains an integer and each node is linked forward to the next

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site