Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I'm having errors. most of them are saying unrecognized token and I see the error happening everytime There is an arrow in the code. This

I'm having errors. most of them are saying "unrecognized token" and I see the error happening everytime There is an arrow in the code.

This is my code

THIS IS THE HEADER FINE

#ifndef DLINKEDLIST_H

#define DLINKEDLIST_H

#include

typedef std::string Elem;// list element type

class DNode

{// doubly linked list node

private:

Elem elem;// node element value

DNode* prev;// previous node in list

DNode* next;// next node in list

friend class DLinkedList;// allow DLinkedList access

};

class DLinkedList {// doubly linked list

public:

DLinkedList();// constructor

~DLinkedList();// destructor

bool empty() const;// is list empty?

const Elem& front() const;// get front element

const Elem& back() const;// get back element

void addFront(const Elem& e);// add to front of list

void addBack(const Elem& e);// add to back of list

void removeFront();// remove from front

void removeBack();// remove from back

private:// local type definitions

DNode* header; // list sentinels

DNode* trailer;

protected:// local utilities

void add(DNode* v, const Elem& e);// insert new node before v

void remove(DNode* v);// remove node v

};

#endif

THIS IS THE CPP FILE

#include

#include

#include

#include

#include "DLinkedList.hpp"

#include

DNode::DNode()

{}

DLinkedList::DLinkedList() {// constructor

header = new DNode; // create sentinels

trailer = new DNode;

header>next = trailer;// have them point to each other

trailer>prev = header;

}

DLinkedList::~DLinkedList() {// destructor

while (!empty()) removeFront();// remove all but sentinels

delete header;// remove the sentinels

delete trailer;

}

bool DLinkedList::empty() const// is list empty?

{ return (header>next == trailer); }

const Elem& DLinkedList::front() const// get front element

{ return header>next>elem; }

const Elem& DLinkedList::back() const// get back element

{ return trailer>prev>elem; }

void DLinkedList::add(DNode* v, const Elem& e) {

DNode* u = new DNode; u>elem = e; // create a new node for e

u>next = v;// link u in between v

u>prev = v>prev;// . . .and v->prev

v>prev>next = v>prev = u;

}

void DLinkedList::addFront(const Elem& e) // add to front of list

{ add(header>next, e); }

void DLinkedList::addBack(const Elem& e) // add to back of list

{ add(trailer, e); }

void DLinkedList::remove(DNode* v) {// remove node v

DNode* u = v>prev;// predecessor

DNode* w = v>next;// successor

u>next = w;// unlink v from list

w>prev = u;

delete v;

}

void DLinkedList::removeFront()// remove from font

{ remove(header>next); }

void DLinkedList::removeBack()// remove from back

{ remove(trailer>prev); }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Basics Computer EngineeringInformation Warehouse Basics From Science

Authors: Odiljon Jakbarov ,Anvarkhan Majidov

1st Edition

620675183X, 978-6206751830

More Books

Students also viewed these Databases questions

Question

1. Write down two or three of your greatest strengths.

Answered: 1 week ago