Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Data Structure in C++ Doubly Linked Lists of ints This is my code below: dlist.c

ID: 3811984 • Letter: D

Question

Data Structure in C++

Doubly Linked Lists of ints

This is my code below: dlist.cc

-------------------------------------------------------------------------------------------------------

#include <iostream>
#include "dlist.h"

dlist::node* dlist::at(int n){
node* c = _head;
while(n > 0 && c){
c = c->next;
n--;
}
return c;
}

void dlist::insert(node* previous, int value){
node* n = new node{value, previous->next};
previous->next = n;
}//update tail

void dlist::del(node* which){
node* nn = which->next;
which->next = nn->next;
delete nn;
}

void dlist::push_back(int value){
node* n = new node{value, nullptr};
_tail->next = n;
_tail-> n;
}

void dlist::push_front(int value){
node* n = new node(value, nullptr);
_head->prev = n;
_head-> n;

}

void dlist::pop_front(){
node* n = _head;
_head = _head->next;
delete n;
}

void dlist::pop_back(){
node* n = _tail;
_tail = _tail->prev;
delete n;
}

int dlist::size() {
node* c = _head;
int s = 0;
while(c){
s++;
c = c->next;
}
return s;
}

--------------------------------------------------------------------------------

Please fix and complete my code, and I also need whole code contatining main function(list_tests.cc) for testing dlist.cc

--------------------------------------------------------------------------------

Output I need:

In this assignment, you will implement a doubly-linked list class. together with some list operations. To make things easier, you'll implement a list of int rather than a template class pragma once dlist. h Doubly linked lists of ints include Kostream class dlist public: d list struct node int value node next node prev; node' head() const return -head; node" tail() const t return -tail Implement ALL the following methods Returns the node at a particular index (0 is the head node at(int) Insert a new value, after an existing one void insert(node *previous int value Delete the given node void del (node which)

Explanation / Answer

dlist.h

======================

class Dlist
{
  
public:
   Dlist();

  
   struct node
   {
       int value;
       node *next;
       node *prev;
   };
   node *_head;
   node* _tail;
   void insert(int value);
   void show();
  
   bool empty();
    node * head(){

return _head;
   }
};

dlist.cpp

==============================

#include "dlist.h"
#include <QDebug>
Dlist::Dlist()
{
   _head = '';
}
bool Dlist::empty()
{
   if(_head == '')
       return true;
   return false;
}
void Dlist::show()
{
   node *temp;
   if(empty())
       qDebug()<<"list is empty";
   else
   {
       temp=_head;
       while(temp )
       {
           qDebug()<<temp->value;
           temp = temp->next;
       }
   }
}
void Dlist::insert(int value)
{
   struct node *link = (struct node*) new(struct node);
   link->value = value;
   link->next ='';
   link->prev = '';
   if(empty()) {
      //make it the last link
      _head = link;
   } else {
      //make link a new last link
      _tail->next = link;   
    
      //mark old last node as prev of new link
      link->prev = _tail;
   }

   //point last to new last node
   _tail = link;
}

main.cpp

#include<QDebug>

#include "dlist.h"
void main()
{
   Dlist odlist;
   odlist.insert(1);
   odlist.insert(2);
   odlist.insert(11);
   odlist.show();
}