Using C++ language, Design and implement a class representing a doubly linked list. The class must have the following requirements:
#include<bits/stdc++.h>
using namespace std;
template<class T>
struct node {
node<T>* next;
node<T>* prev;
T data;
};
template<class T>
class DDL {
private:
node<T> *next;
node<T> *prev;
node<T> *first;
node<T> *last;
node<T> *current;
int size = 0;
public:
DDL<T>()
{
next =
NULL;
prev =
NULL;
first =
NULL;
last =
NULL;
current =
NULL;
}
DDL<T>(const DDL<T>
&D)
{
first =
D.first;
last =
D.last;
next =
D.next;
prev =
D.prev;
current =
D.current;
size =
D.size;
}
void push_back(T d)
{
size++;
if(!first)
{
// The list is
empty
first = new
node<T>;
first->data =
d;
first->next =
NULL;
first->prev =
NULL;
last =
first;
current =
first;
} else {
// The list
isn't empty
if(last ==
first) {
// The list has one element
last = new node<T>;
last->data = d;
last->next = NULL;
last->prev = first;
first->next = last;
current = last;
} else {
// The list has more than one element
node<T>* insdata = new
node<T>;
insdata->data = d;
insdata->next = NULL;
last->next = insdata;
insdata->prev = last;
last = insdata;
current = last;
}
}
}
void push_front(T d)
{
size++;
if(!last)
{
// The list is
empty
last = new
node<T>;
last->data =
d;
last->next =
NULL;
last->prev =
NULL;
first =
last;
current =
first;
} else {
// The list
isn't empty
if(last ==
first) {
// The list has one element
first = new node<T>;
first->data = d;
first->prev = NULL;
first->next = last;
first->prev = first;
current = first;
} else {
// The list has more than one element
node<T>* insdata = new
node<T>;
insdata->data = d;
insdata->prev = NULL;
last->next = insdata;
insdata->next = first;
first = insdata;
current = first;
}
}
}
T get()
{
return
this->current.data;
}
T get(int index) {
if(index == 0)
{
// Get the first element
return this->first->data;
} else {
// Get the index'th element
node<T>* curr = this->first;
for(int i = 0; i < index; ++i) {
curr = curr->next;
}
return curr->data;
}
}
int length()
{
return
size;
}
T operator[](int index) {
return
get(index);
}
~DDL() { }
};
int main()
{
DDL<int> p;
for(int i=0;i<10;i++)
p.push_front(i+1);
DDL<int> head = p;
for(int i=0;i<head.length();i++)
cout<<head[i]<<endl;
return 0;
}
Using C++ language, Design and implement a class representing a doubly linked list. The class must...
PART 1: Design and implement a class representing a doubly linked list. The class must have the following requirements: 1)The linked list and the nodes must be implemented as C++ templates 2)The list must be generic
In c++ language
Design and implement a Queue data structure using linked list. Support the following usual operations: default constructor parameterized constructor to create a queue of user-specified capacity enqueue dequeue is_full is_empty display destructor that deallocates all the nodes copy constructor overloaded assignment operator Demonstrate using a main function.
Implement a simple Doubly Linked List using nodes. Functions to include: an insert in a sorted list, and a delete function, including constructor. Please include comments to make the code traceable and understandable
You need to implement a queue based on the doubly linked list. (In C++) **PLEASE follow the format** **Don't worry about the readme.txt** THANK YOU SO SO MUCH! You have to implement the doubly linked list in DList.h and DList.cpp and the queue in the LinkedQueue.h and LinkedQueue.cpp; all as template classes. You have to provide the main.cpp file as we discussed in class to allow the user to interact with your queue using enqueue, dequeue, front, back, size, empty,...
(The SortedLinkedList class template) Complete the SortedLinkedList class template which is a doubly linked list and is implemented with a header node and a tail node. // SortedLinkedList.h // SortedLinkedList.h // A collection of data are stored in the list by ascending order #ifndef SORTEDLIST_H #define SORTEDLIST_H using namespace std; template <typename T> class SortedList { private: // The basic single linked list node type. // Nested inside of SortedList. struct NodeType { T data; NodeType* next; NodeType* prev; NodeType(const...
C++ queue data sructure ising linked list.
Design and implement a Queue data structure using linked list. Support the following usual operations: (a) default constructor (b) parameterized constructor to create a queue of user-specified capacity (c) enqueue (d) dequeue (e) is_full (f) is_empty display (h) destructor that deallocates all nodes (i) copy constructor (j) overloaded assignment operator Demonstrate using a main function.
Using C++ • Implement the following in both string linked list and in the template version of the class: • Add to the back and remove from back of the list : - void addBack(….); - string removeBack(); E removeBack(…); • Insert elements in a sorted list i.e., find the position where an element fits and add it to the list. Note you must call the addBack and addFront functions if you insert in the front or rare of the...
Write a C++implementation of a doubly linked list class using a template class representation for a node and using pointers.In its public API provide functions to insert,find, delete, get size and get position of an element. Write C++ code to show those functions work as expected. (MUST COMPILE AND RUN)
C++ Implement a class template for a LinkedList.(doubly linked). Also, your class will have a tailPtr in addition to a headPtr along with methods to get, set, insert and remove values at either end of the list. Call these getFirst, getLast, setFirst, setLast, insertFirst, insertLast, removeFirst, removeLast. Don't forget, you also need a copy constructor and destructor plus getLength, isEmpty and clear methods. Overload the stream insertion operator as a friend function which outputs the list in format { 1,...
QUESTION 1: Queue Class: Write a Queue class using doubly-linked structure and implement the following functionalities. enqueue (inserts element to the end) dequeue (removes the front element and provides content) isEmpty (checks whether the Queue is empty or not) makeEmpty () peek (provides the element sitting at the top/front, but does not remove) print (prints all the elements from front to the end) reversePrint(prints all the elements from end to the front with the help of back pointers inside your...