Design and implement a class representing an unsorted doubly linked list. The cl
ID: 3830475 • Letter: D
Question
Design and implement a class representing an unsorted doubly linked list. The class must have the following requirements: The linked list and the nodes must be implemented as a C + + templates 1. The list must be generic - it should not implement arithmetic/logic function. 2. It must include a destructor, a copy constructor and the overload operation. 3. It must include function to insert at the front and at the back of the list 4. It must include a function to return the length of the list 5. It must provide an iterator - based interface for the user from front to back a. A front iterator pointer b. Function to reset the interface, walk the iterator and return the info of the iterator 6 It must include an iterator - based interface for the user from back to front a. A back iterator pointer b. Functions to reset the iterator, walk the iterator and return the info of the iterator The implementation of the class Largelnt will use a dynamic physical structure to store the individual digits of an integer, and will provide some basic I/O and arithmetic operations that can be performed on integers. In particular, the class should include: A default constructor 1) An operator function to overload the operator^+ 2) An operator function to overload the operator = 3) A friend operator function to overload the operator 5) An object of the doubly linked list class representing the large integer 6) An int field specifying the length of the large integerExplanation / Answer
-A doubly-linked list is a linked data structure that consists of a set of sequentially linked records called nodes.
- Each node contains two fields called links
-They are references to the previous and to the next node in the sequence of nodes.
#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
struct node
{
int info;
struct node *next;
struct node *prev;
}*start;
/*
Class Declaration
*/
class doule_linked_list
{
public:
void insert_begin(int value);
void insert_after(int value, int position);
void sizeof_list(int value);
void destructor();
void copy();
void reverse();
double_llist()
{
start = NULL;
}
};
int main()
{
int choice, element, position;
double_llist dl;
while (1)
{
cout<<endl<<"TPM CODE FOR DOUBLE LINK LIST OPERATION CHEGG"<<endl;
//here I am using a switch function for portraying all aspects of double link which is requested in question
cout<<"node creation"<<endl;
cout<<"Insert at front “<<endl;
cout<<"Insert at back "<<endl;
cout<<"Legth of the list"<<endl;
cout<<"destructor display"<<endl;
cout<<"copy construtor"<<endl;
cout<<"choice : ";
cin>>choice;
switch ( choice )
{
case 1:
cout<<"Enter data: ";
cin>>element;
dl.create_list(element);
cout<<endl;
break;
case 2:
cout<<"Enter data: ";
cin>>element;
dl.add_begin(element);
cout<<endl;
break;
case 3:
cout<<"Enter data: ";
cin>>element;
cout<<"Insert Element after postion: ";
cin>>position;
dl.add_after(element, position);
cout<<endl;
break;
case 4:
void sizeof_list() {
int size = 0;
struct node *link;
if(head==NULL) {
printf(" Size of list is %d ", size);
return;
}
link = head;
while(link != NULL) {
link = link->next;
size++;
}
printf("list size is", size);
}
cout<<endl;
break;
case 5:
struct node* temp;
while (first != NULL)
{
temp = first->next;
delete first;
first = temp;
}
break;
case 6:
//call copy construtor
dl.count();
break;
//copy constructor
List<T>::List(const T& other) {
//if the list is empty then
if (other.head == NULL) {
head = NULL;
tail = NULL;
count = 0;
}
else {
head = new Node<T>;
head -> setNext(head);
head -> setPrevious(head);
// Copy the original list
Node<T>* ptr = other.head->next();
while (ptr != other.head) {
rearInsert(ptr->data());
ptr = ptr->next();
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.