SlideShare a Scribd company logo
I can't find the error in which my double linked list won't display help me pls
#include
using namespace std;
typedef string Elem;
class DNode {
private:
Elem elem;
DNode* prev;
DNode* next;
friend class DLinkedList;
};
class DLinkedList {
public:
DLinkedList();
~DLinkedList();
bool empty() const;
const Elem& front() const;
const Elem& back() const;
void addFront(const Elem& e);
void addBack(const Elem& e);
void removeFront();
void removeBack();
void print(); // prints the doubly linked list
void insertElem(const Elem& e); // inserts element e in ascending order
void deleteElem(const Elem& e); // deletes element e
private:
DNode* header;
DNode* trailer;
protected:
void add(DNode* v, const Elem& e);
void remove(DNode* v);
};
DLinkedList::DLinkedList() {
header = new DNode;
trailer = new DNode;
header->next = trailer;
trailer->prev = header;
}
DLinkedList::~DLinkedList() {
while (!empty()) removeFront();
delete header;
delete trailer;
}
bool DLinkedList::empty() const {
return (header->next == trailer);
}
const Elem& DLinkedList::front() const {
return header->next->elem;
}
const Elem& DLinkedList::back() const {
return trailer->prev->elem;
}
void DLinkedList::add(DNode* v, const Elem& e) {
DNode* u = new DNode;
u->elem = e;
u->next = v;
u->prev = v->prev;
v->prev->next = v->prev = u;
}
void DLinkedList::addFront(const Elem& e) {
add(header->next, e);
}
void DLinkedList::addBack(const Elem& e) {
add(trailer, e);
}
void DLinkedList::remove(DNode* v) {
DNode* u = v->prev;
DNode* w = v->next;
u->next = w;
w->prev = u;
delete v;
}
void DLinkedList::removeFront() {
remove(header->next);
}
void DLinkedList::removeBack() {
remove(trailer->prev);
}
void DLinkedList::print() {
DNode* cur = header->next; // First element in the list is header->next
while (cur != trailer) { // Loop until the end is not reached
cout<elem<<" "; // Print the element
cur = cur->next; // Increment the pointer
}
cout<next;
while (cur != trailer && cur->elem < e) { // Loop until end of list or current element becomes
equal to or more than e
cur = cur->next;
}
add(cur, e); // Add e just before cur
}
void DLinkedList::deleteElem(const Elem& e) {
DNode* cur = header->next;
while (cur != trailer && cur->elem != e) { // Loop until end of list or current element matches e
cur = cur->next;
}
if (cur != trailer) { // If element is found
remove(cur); // Remove this node
}
}
int main() {
DLinkedList dlist;
dlist.addFront("c");
dlist.addFront("a");
dlist.addBack("d");
dlist.print(); // prints a c d
dlist.insertElem("b");
dlist.print(); // prints a b c d
dlist.deleteElem("d");
dlist.print(); // prints a b c
return 0;
}

More Related Content

PDF
1- The design of a singly-linked list below is a picture of the functi (1).pdf
PPTX
Data Structures and Agorithm: DS 05 Doubly Linked List.pptx
PDF
Using the provided table interface table.h and the sample linked lis.pdf
DOCX
Below is a depiction of a doubly-linked list implementation of the bag.docx
PDF
C++ Program to Implement Doubly Linked List #includei.pdf
PDF
could you implement this function please, im having issues with it..pdf
PDF
JAVA A double-ended queue is a list that allows the addition and.pdf
PDF
Write a program to implement below operations with both singly and d.pdf
1- The design of a singly-linked list below is a picture of the functi (1).pdf
Data Structures and Agorithm: DS 05 Doubly Linked List.pptx
Using the provided table interface table.h and the sample linked lis.pdf
Below is a depiction of a doubly-linked list implementation of the bag.docx
C++ Program to Implement Doubly Linked List #includei.pdf
could you implement this function please, im having issues with it..pdf
JAVA A double-ended queue is a list that allows the addition and.pdf
Write a program to implement below operations with both singly and d.pdf

Similar to I cant find the error in which my double linked list wont display .pdf (20)

PDF
#includeiostream#includecstdio#includecstdlib Node .pdf
DOCX
There are a number of errors in the following program- All errors are.docx
PDF
Selenium Locators groups 1_0_2
PDF
Locators groups 1_0_2
PDF
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
PDF
Qestion Please add pre-condition, post-conditions and descriptions .pdf
PDF
Please need help on following program using c++ language. Please inc.pdf
PDF
I need help implementing a Stack with this java programming assignme.pdf
PDF
Problem- Describe an algorithm for concatenating two singly linked lis.pdf
PDF
C++ projectMachine Problem 7 - HashingWrite a program to do the .pdf
DOCX
4) 15 points- Linked Lists- Consider the linked list template-type.docx
PDF
please help me in C++Objective Create a singly linked list of num.pdf
PDF
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
PDF
#includeiostream#includecstdio#includecstdlibusing names.pdf
DOCX
#include iostream#include d_node.h #include d_nodel.h.docx
DOCX
Write a C++ function that delete nodes in a doubly linkedlist- It shou.docx
DOCX
Add functions push(int n- Deque &dq) and pop(Deque &dq)- Functions pus.docx
PDF
Hi,I have added the methods and main class as per your requirement.pdf
PDF
Problem- Describe an algorithm for concatenating two singly linked lis.pdf
PDF
Using the header(dlist) and mainline file (dlistapp) belowYou are .pdf
#includeiostream#includecstdio#includecstdlib Node .pdf
There are a number of errors in the following program- All errors are.docx
Selenium Locators groups 1_0_2
Locators groups 1_0_2
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
Qestion Please add pre-condition, post-conditions and descriptions .pdf
Please need help on following program using c++ language. Please inc.pdf
I need help implementing a Stack with this java programming assignme.pdf
Problem- Describe an algorithm for concatenating two singly linked lis.pdf
C++ projectMachine Problem 7 - HashingWrite a program to do the .pdf
4) 15 points- Linked Lists- Consider the linked list template-type.docx
please help me in C++Objective Create a singly linked list of num.pdf
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
#includeiostream#includecstdio#includecstdlibusing names.pdf
#include iostream#include d_node.h #include d_nodel.h.docx
Write a C++ function that delete nodes in a doubly linkedlist- It shou.docx
Add functions push(int n- Deque &dq) and pop(Deque &dq)- Functions pus.docx
Hi,I have added the methods and main class as per your requirement.pdf
Problem- Describe an algorithm for concatenating two singly linked lis.pdf
Using the header(dlist) and mainline file (dlistapp) belowYou are .pdf
Ad

More from allystraders (20)

PDF
Supplemental knowledge conversion processes have been added to the E.pdf
PDF
Supongamos que Musashi, un economista de un programa de radio AM, y .pdf
PDF
Suponga que las tasas de inter�s en los Estados Unidos, pero no aume.pdf
PDF
Suponga que la ARN polimerasa estaba transcribiendo un gen eucari�ti.pdf
PDF
Suppose researchers are about to draw a sample of 1450 observations .pdf
PDF
Suponga que el Congreso est� considerando un proyecto de ley que imp.pdf
PDF
Suppose that there are two groups of people in the economy. In group.pdf
PDF
Suppose that the Fed will increase the money supply. Which of the fo.pdf
PDF
Suppose that the body weights of Roborovski dwarf hamsters are norma.pdf
PDF
Suppose that in a particular country, the TFR fell to zero and remai.pdf
PDF
Suppose that disposable income, consumption, and saving in some coun.pdf
PDF
Suppose that 60 of students at Kansas State University have listene.pdf
PDF
Suppose Maria and Jamal both face the following individual loss dist.pdf
PDF
Suppose a random variable X has the following probability distributi.pdf
PDF
Suppose a country had a smaller increase in debt in 2011 than it had.pdf
PDF
how would implement empowerment techniques within a service Choose .pdf
PDF
How were the management controls at Siemens prior to the Bribery sca.pdf
PDF
How would I create this diagramRentTool Viewpoints � Technology .pdf
PDF
How well did Thaldorf interact with each member of the DMUOn what.pdf
PDF
How do increasing atmospheric CO2 emissions threaten sea creatures, .pdf
Supplemental knowledge conversion processes have been added to the E.pdf
Supongamos que Musashi, un economista de un programa de radio AM, y .pdf
Suponga que las tasas de inter�s en los Estados Unidos, pero no aume.pdf
Suponga que la ARN polimerasa estaba transcribiendo un gen eucari�ti.pdf
Suppose researchers are about to draw a sample of 1450 observations .pdf
Suponga que el Congreso est� considerando un proyecto de ley que imp.pdf
Suppose that there are two groups of people in the economy. In group.pdf
Suppose that the Fed will increase the money supply. Which of the fo.pdf
Suppose that the body weights of Roborovski dwarf hamsters are norma.pdf
Suppose that in a particular country, the TFR fell to zero and remai.pdf
Suppose that disposable income, consumption, and saving in some coun.pdf
Suppose that 60 of students at Kansas State University have listene.pdf
Suppose Maria and Jamal both face the following individual loss dist.pdf
Suppose a random variable X has the following probability distributi.pdf
Suppose a country had a smaller increase in debt in 2011 than it had.pdf
how would implement empowerment techniques within a service Choose .pdf
How were the management controls at Siemens prior to the Bribery sca.pdf
How would I create this diagramRentTool Viewpoints � Technology .pdf
How well did Thaldorf interact with each member of the DMUOn what.pdf
How do increasing atmospheric CO2 emissions threaten sea creatures, .pdf
Ad

Recently uploaded (20)

PPTX
GDM (1) (1).pptx small presentation for students
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
Complications of Minimal Access Surgery at WLH
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
A systematic review of self-coping strategies used by university students to ...
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
master seminar digital applications in india
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
RMMM.pdf make it easy to upload and study
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
GDM (1) (1).pptx small presentation for students
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
Complications of Minimal Access Surgery at WLH
Anesthesia in Laparoscopic Surgery in India
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Final Presentation General Medicine 03-08-2024.pptx
A systematic review of self-coping strategies used by university students to ...
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
O7-L3 Supply Chain Operations - ICLT Program
master seminar digital applications in india
Module 4: Burden of Disease Tutorial Slides S2 2025
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
Final Presentation General Medicine 03-08-2024.pptx
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
RMMM.pdf make it easy to upload and study
102 student loan defaulters named and shamed – Is someone you know on the list?
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf

I cant find the error in which my double linked list wont display .pdf

  • 1. I can't find the error in which my double linked list won't display help me pls #include using namespace std; typedef string Elem; class DNode { private: Elem elem; DNode* prev; DNode* next; friend class DLinkedList; }; class DLinkedList { public: DLinkedList(); ~DLinkedList(); bool empty() const; const Elem& front() const; const Elem& back() const; void addFront(const Elem& e); void addBack(const Elem& e); void removeFront(); void removeBack(); void print(); // prints the doubly linked list void insertElem(const Elem& e); // inserts element e in ascending order void deleteElem(const Elem& e); // deletes element e private: DNode* header; DNode* trailer; protected: void add(DNode* v, const Elem& e); void remove(DNode* v);
  • 2. }; DLinkedList::DLinkedList() { header = new DNode; trailer = new DNode; header->next = trailer; trailer->prev = header; } DLinkedList::~DLinkedList() { while (!empty()) removeFront(); delete header; delete trailer; } bool DLinkedList::empty() const { return (header->next == trailer); } const Elem& DLinkedList::front() const { return header->next->elem; } const Elem& DLinkedList::back() const { return trailer->prev->elem; } void DLinkedList::add(DNode* v, const Elem& e) { DNode* u = new DNode; u->elem = e; u->next = v; u->prev = v->prev; v->prev->next = v->prev = u; }
  • 3. void DLinkedList::addFront(const Elem& e) { add(header->next, e); } void DLinkedList::addBack(const Elem& e) { add(trailer, e); } void DLinkedList::remove(DNode* v) { DNode* u = v->prev; DNode* w = v->next; u->next = w; w->prev = u; delete v; } void DLinkedList::removeFront() { remove(header->next); } void DLinkedList::removeBack() { remove(trailer->prev); } void DLinkedList::print() { DNode* cur = header->next; // First element in the list is header->next while (cur != trailer) { // Loop until the end is not reached cout<elem<<" "; // Print the element cur = cur->next; // Increment the pointer } cout<next; while (cur != trailer && cur->elem < e) { // Loop until end of list or current element becomes equal to or more than e cur = cur->next; }
  • 4. add(cur, e); // Add e just before cur } void DLinkedList::deleteElem(const Elem& e) { DNode* cur = header->next; while (cur != trailer && cur->elem != e) { // Loop until end of list or current element matches e cur = cur->next; } if (cur != trailer) { // If element is found remove(cur); // Remove this node } } int main() { DLinkedList dlist; dlist.addFront("c"); dlist.addFront("a"); dlist.addBack("d"); dlist.print(); // prints a c d dlist.insertElem("b"); dlist.print(); // prints a b c d dlist.deleteElem("d"); dlist.print(); // prints a b c return 0; }