SlideShare a Scribd company logo
DoublyList.cpp:
#include "DoublyList.h"
using namespace std;
void DoublyList::insertFront(int newData)
{
if (first == nullptr)
{
first = new DLLNode(newData, nullptr, nullptr);
last = first;
// Common error: Forgetting to reset pointer last.
}
else
{
first = new DLLNode(newData, nullptr, first);
first->getNext()->setPrev(first);
// Common error: Forgetting to connect pointer
// prev of what is now the second node to the
// new first node.
}
++count;
}
void DoublyList::printForward() const
{
DLLNode* current = first;
while (current != nullptr)
{
cout << current->getData() << " ";
current = current->getNext();
}
}
void DoublyList::printReverse() const
{
DLLNode* current = last;
while (current != nullptr)
{
cout << current->getData() << " ";
current = current->getPrev();
}
}
void DoublyList::clearList()
{
DLLNode* temp = first;
while (first != nullptr)
{
first = first->getNext();
delete temp;
temp = first;
}
last = nullptr;
// Don't forget to reset pointer last to nullptr.
count = 0;
}
DoublyList::~DoublyList()
{
if (first != nullptr)
clearList();
}
DoublyList.h
#ifndef DOUBLYLIST_H
#define DOUBLYLIST_H
#include <string>
#include <iostream>
class DLLNode
{
public:
DLLNode() : data(0), prev(nullptr), next(nullptr) {}
DLLNode(int theData, DLLNode* prevLink, DLLNode* nextLink)
: data(theData), prev(prevLink), next(nextLink) {}
int getData() const { return data; }
DLLNode* getPrev() const { return prev; }
DLLNode* getNext() const { return next; }
void setData(int theData) { data = theData; }
void setPrev(DLLNode* prevLink) { prev = prevLink; }
void setNext(DLLNode* nextLink) { next = nextLink; }
~DLLNode(){}
private:
int data; // To simplify, we are using only one piece of data.
DLLNode* prev;
DLLNode* next;
};
class DoublyList
{
public:
DoublyList() : first(nullptr), last(nullptr), count(0) {}
void insertFront(int newData);
void printForward() const;
void printReverse() const;
void rotateNodesRight(int);
void clearList();
~DoublyList();
private:
// Pointer to the first node in the list.
DLLNode*first;
// Pointer to the last node in the list.
DLLNode*last;
// Number of nodes in the list.
int count;
};
#endif
Main.cpp
#include "DoublyList.h"
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<vector<int>> data = {
{25, 76, 35, 67, 15, 98},
{1, 2, 3, 4, 5, 6, 7, 8, 9},
{10, 20},
{34, 56, 78, 12, 89, 34, 76, 28, 54, 22, 41},
{123, 873, 619},
};
vector<int> nodesToRotate = { 2, 3, 1, 9, 2 };
{
DoublyList doublyList;
int vectorSize = static_cast<int>(data.size());
for (int i = 0; i < vectorSize; ++i)
{
int innerSize = static_cast<int>(data[i].size());
for (int j = innerSize - 1; j >= 0; --j)
doublyList.insertFront(data[i].at(j));
cout << "Rotate right: " << nodesToRotate[i] << "n";
cout << " List is: ";
doublyList.printForward();
cout << "n";
doublyList.rotateNodesRight(nodesToRotate[i]);
cout << "After rotating:";
cout << "n Print forward: ";
doublyList.printForward();
cout << "nPrint backwards: ";
doublyList.printReverse();
cout << "nn";
doublyList.clearList();
}
}
cout << "n";
system("Pause");
return 0;
Function rotateNodesRight() - This function is a member function of the class DoublyList. -
Parameter: An int that stores the number of times that the rotation occurs. - The function works
as the previous one, with the difference that the rotation occurs to the right. Again, this is about
resetting pointers, not about moving data. - Example Page 4 of 5 List is: 257635671598
Parameter is: 2 After rotating, list is: 15 98 25 76 35 67 - Assumptions - The list has at least 2
elements. - The parameter is always smaller than the number of elements in the list. -
Restrictions: - Cannot create helper functions.
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
Ad

More Related Content

Similar to DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf (20)

Statistics.cpp
Statistics.cppStatistics.cpp
Statistics.cpp
Vorname Nachname
 
Data structures cs301 power point slides lecture 03
Data structures   cs301 power point slides lecture 03Data structures   cs301 power point slides lecture 03
Data structures cs301 power point slides lecture 03
Nasir Mehmood
 
C++ programs
C++ programsC++ programs
C++ programs
Mukund Gandrakota
 
Look Ma, “update DB to HTML5 using C++”, no hands! 
Look Ma, “update DB to HTML5 using C++”, no hands! Look Ma, “update DB to HTML5 using C++”, no hands! 
Look Ma, “update DB to HTML5 using C++”, no hands! 
aleks-f
 
Data struture lab
Data struture labData struture lab
Data struture lab
krishnamurthy Murthy.Tt
 
C++ file
C++ fileC++ file
C++ file
simarsimmygrewal
 
maincpp include ListItemh include ltstringgt in.pdf
maincpp include ListItemh include ltstringgt in.pdfmaincpp include ListItemh include ltstringgt in.pdf
maincpp include ListItemh include ltstringgt in.pdf
abiwarmaa
 
Chainer-Compiler 動かしてみた
Chainer-Compiler 動かしてみたChainer-Compiler 動かしてみた
Chainer-Compiler 動かしてみた
Akira Maruoka
 
Data Structure in C++Doubly Linked Lists of ints httpstaffwww.pdf
Data Structure in C++Doubly Linked Lists of ints httpstaffwww.pdfData Structure in C++Doubly Linked Lists of ints httpstaffwww.pdf
Data Structure in C++Doubly Linked Lists of ints httpstaffwww.pdf
jyothimuppasani1
 
Zoro123456789123456789123456789123456789
Zoro123456789123456789123456789123456789Zoro123456789123456789123456789123456789
Zoro123456789123456789123456789123456789
Ghh
 
labb123456789123456789123456789123456789
labb123456789123456789123456789123456789labb123456789123456789123456789123456789
labb123456789123456789123456789123456789
Ghh
 
C++ lectures all chapters in one slide.pptx
C++ lectures all chapters in one slide.pptxC++ lectures all chapters in one slide.pptx
C++ lectures all chapters in one slide.pptx
ssuser3cbb4c
 
Lab. Programs in C
Lab. Programs in CLab. Programs in C
Lab. Programs in C
Saket Pathak
 
CUDA First Programs: Computer Architecture CSE448 : UAA Alaska : Notes
CUDA First Programs: Computer Architecture CSE448 : UAA Alaska : NotesCUDA First Programs: Computer Architecture CSE448 : UAA Alaska : Notes
CUDA First Programs: Computer Architecture CSE448 : UAA Alaska : Notes
Subhajit Sahu
 
Program flowchart
Program flowchartProgram flowchart
Program flowchart
Sowri Rajan
 
54602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee0108310154602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee01083101
premrings
 
Oops lab manual2
Oops lab manual2Oops lab manual2
Oops lab manual2
Mouna Guru
 
Lecture11 standard template-library
Lecture11 standard template-libraryLecture11 standard template-library
Lecture11 standard template-library
Hariz Mustafa
 
Object Oriented Programming Using C++: C++ Namespaces.pptx
Object Oriented Programming Using C++: C++ Namespaces.pptxObject Oriented Programming Using C++: C++ Namespaces.pptx
Object Oriented Programming Using C++: C++ Namespaces.pptx
RashidFaridChishti
 
Go vs C++ - CppRussia 2019 Piter BoF
Go vs C++ - CppRussia 2019 Piter BoFGo vs C++ - CppRussia 2019 Piter BoF
Go vs C++ - CppRussia 2019 Piter BoF
Timur Safin
 
Data structures cs301 power point slides lecture 03
Data structures   cs301 power point slides lecture 03Data structures   cs301 power point slides lecture 03
Data structures cs301 power point slides lecture 03
Nasir Mehmood
 
Look Ma, “update DB to HTML5 using C++”, no hands! 
Look Ma, “update DB to HTML5 using C++”, no hands! Look Ma, “update DB to HTML5 using C++”, no hands! 
Look Ma, “update DB to HTML5 using C++”, no hands! 
aleks-f
 
maincpp include ListItemh include ltstringgt in.pdf
maincpp include ListItemh include ltstringgt in.pdfmaincpp include ListItemh include ltstringgt in.pdf
maincpp include ListItemh include ltstringgt in.pdf
abiwarmaa
 
Chainer-Compiler 動かしてみた
Chainer-Compiler 動かしてみたChainer-Compiler 動かしてみた
Chainer-Compiler 動かしてみた
Akira Maruoka
 
Data Structure in C++Doubly Linked Lists of ints httpstaffwww.pdf
Data Structure in C++Doubly Linked Lists of ints httpstaffwww.pdfData Structure in C++Doubly Linked Lists of ints httpstaffwww.pdf
Data Structure in C++Doubly Linked Lists of ints httpstaffwww.pdf
jyothimuppasani1
 
Zoro123456789123456789123456789123456789
Zoro123456789123456789123456789123456789Zoro123456789123456789123456789123456789
Zoro123456789123456789123456789123456789
Ghh
 
labb123456789123456789123456789123456789
labb123456789123456789123456789123456789labb123456789123456789123456789123456789
labb123456789123456789123456789123456789
Ghh
 
C++ lectures all chapters in one slide.pptx
C++ lectures all chapters in one slide.pptxC++ lectures all chapters in one slide.pptx
C++ lectures all chapters in one slide.pptx
ssuser3cbb4c
 
Lab. Programs in C
Lab. Programs in CLab. Programs in C
Lab. Programs in C
Saket Pathak
 
CUDA First Programs: Computer Architecture CSE448 : UAA Alaska : Notes
CUDA First Programs: Computer Architecture CSE448 : UAA Alaska : NotesCUDA First Programs: Computer Architecture CSE448 : UAA Alaska : Notes
CUDA First Programs: Computer Architecture CSE448 : UAA Alaska : Notes
Subhajit Sahu
 
Program flowchart
Program flowchartProgram flowchart
Program flowchart
Sowri Rajan
 
54602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee0108310154602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee01083101
premrings
 
Oops lab manual2
Oops lab manual2Oops lab manual2
Oops lab manual2
Mouna Guru
 
Lecture11 standard template-library
Lecture11 standard template-libraryLecture11 standard template-library
Lecture11 standard template-library
Hariz Mustafa
 
Object Oriented Programming Using C++: C++ Namespaces.pptx
Object Oriented Programming Using C++: C++ Namespaces.pptxObject Oriented Programming Using C++: C++ Namespaces.pptx
Object Oriented Programming Using C++: C++ Namespaces.pptx
RashidFaridChishti
 
Go vs C++ - CppRussia 2019 Piter BoF
Go vs C++ - CppRussia 2019 Piter BoFGo vs C++ - CppRussia 2019 Piter BoF
Go vs C++ - CppRussia 2019 Piter BoF
Timur Safin
 

More from aathiauto (20)

The challenges of delivering climate change policy at the sub-national.pdf
The challenges of delivering climate change policy at the sub-national.pdfThe challenges of delivering climate change policy at the sub-national.pdf
The challenges of delivering climate change policy at the sub-national.pdf
aathiauto
 
Please give an explanation and show all steps- Thanks 1- Find a- P(Z-2.pdf
Please give an explanation and show all steps- Thanks 1- Find a- P(Z-2.pdfPlease give an explanation and show all steps- Thanks 1- Find a- P(Z-2.pdf
Please give an explanation and show all steps- Thanks 1- Find a- P(Z-2.pdf
aathiauto
 
You are leading a central working group that encompasses representativ.pdf
You are leading a central working group that encompasses representativ.pdfYou are leading a central working group that encompasses representativ.pdf
You are leading a central working group that encompasses representativ.pdf
aathiauto
 
What type of defense is a cough reflex-A Nonspecific- secondary line o.pdf
What type of defense is a cough reflex-A Nonspecific- secondary line o.pdfWhat type of defense is a cough reflex-A Nonspecific- secondary line o.pdf
What type of defense is a cough reflex-A Nonspecific- secondary line o.pdf
aathiauto
 
Twelve jurors are randomly solected from a population of 4 milion resi.pdf
Twelve jurors are randomly solected from a population of 4 milion resi.pdfTwelve jurors are randomly solected from a population of 4 milion resi.pdf
Twelve jurors are randomly solected from a population of 4 milion resi.pdf
aathiauto
 
Use the given discrete probability distribution for the number of head.pdf
Use the given discrete probability distribution for the number of head.pdfUse the given discrete probability distribution for the number of head.pdf
Use the given discrete probability distribution for the number of head.pdf
aathiauto
 
The following graphs represent various types of cost behaviors- Graph.pdf
The following graphs represent various types of cost behaviors- Graph.pdfThe following graphs represent various types of cost behaviors- Graph.pdf
The following graphs represent various types of cost behaviors- Graph.pdf
aathiauto
 
The day after the Oscars- Blue Rose Research conducted a poll of peopl.pdf
The day after the Oscars- Blue Rose Research conducted a poll of peopl.pdfThe day after the Oscars- Blue Rose Research conducted a poll of peopl.pdf
The day after the Oscars- Blue Rose Research conducted a poll of peopl.pdf
aathiauto
 
The Barteimann Corporaton sold iss credit subsidiacy on Detnmber 31 of.pdf
The Barteimann Corporaton sold iss credit subsidiacy on Detnmber 31 of.pdfThe Barteimann Corporaton sold iss credit subsidiacy on Detnmber 31 of.pdf
The Barteimann Corporaton sold iss credit subsidiacy on Detnmber 31 of.pdf
aathiauto
 
Since World War II- national governments have focused on job growth- a.pdf
Since World War II- national governments have focused on job growth- a.pdfSince World War II- national governments have focused on job growth- a.pdf
Since World War II- national governments have focused on job growth- a.pdf
aathiauto
 
Stars on the main sequence obey a mass-luminosity relation- According.pdf
Stars on the main sequence obey a mass-luminosity relation- According.pdfStars on the main sequence obey a mass-luminosity relation- According.pdf
Stars on the main sequence obey a mass-luminosity relation- According.pdf
aathiauto
 
Health Informatics- Theoretical Foundations- and Practice Evolution- D.pdf
Health Informatics- Theoretical Foundations- and Practice Evolution- D.pdfHealth Informatics- Theoretical Foundations- and Practice Evolution- D.pdf
Health Informatics- Theoretical Foundations- and Practice Evolution- D.pdf
aathiauto
 
In what ways are national income statistics usetul-.pdf
In what ways are national income statistics usetul-.pdfIn what ways are national income statistics usetul-.pdf
In what ways are national income statistics usetul-.pdf
aathiauto
 
If a population has a standard deviation of 12- what is the VARIANCE o.pdf
If a population has a standard deviation of 12- what is the VARIANCE o.pdfIf a population has a standard deviation of 12- what is the VARIANCE o.pdf
If a population has a standard deviation of 12- what is the VARIANCE o.pdf
aathiauto
 
Given that over 97- of climate scientists agree that the climate chang.pdf
Given that over 97- of climate scientists agree that the climate chang.pdfGiven that over 97- of climate scientists agree that the climate chang.pdf
Given that over 97- of climate scientists agree that the climate chang.pdf
aathiauto
 
Given this sounding- what kind of convective event would you expect- C.pdf
Given this sounding- what kind of convective event would you expect- C.pdfGiven this sounding- what kind of convective event would you expect- C.pdf
Given this sounding- what kind of convective event would you expect- C.pdf
aathiauto
 
a- Recessions typically hurtb- What is the general trend observed amon.pdf
a- Recessions typically hurtb- What is the general trend observed amon.pdfa- Recessions typically hurtb- What is the general trend observed amon.pdf
a- Recessions typically hurtb- What is the general trend observed amon.pdf
aathiauto
 
Between 2001 and 2009-3730 adults obtained high school diplomas throug.pdf
Between 2001 and 2009-3730 adults obtained high school diplomas throug.pdfBetween 2001 and 2009-3730 adults obtained high school diplomas throug.pdf
Between 2001 and 2009-3730 adults obtained high school diplomas throug.pdf
aathiauto
 
ages -c(20-11-18-5-33).pdf
ages -c(20-11-18-5-33).pdfages -c(20-11-18-5-33).pdf
ages -c(20-11-18-5-33).pdf
aathiauto
 
1a) Which factors are involved in the movement of metals- Give a brief.pdf
1a) Which factors are involved in the movement of metals- Give a brief.pdf1a) Which factors are involved in the movement of metals- Give a brief.pdf
1a) Which factors are involved in the movement of metals- Give a brief.pdf
aathiauto
 
The challenges of delivering climate change policy at the sub-national.pdf
The challenges of delivering climate change policy at the sub-national.pdfThe challenges of delivering climate change policy at the sub-national.pdf
The challenges of delivering climate change policy at the sub-national.pdf
aathiauto
 
Please give an explanation and show all steps- Thanks 1- Find a- P(Z-2.pdf
Please give an explanation and show all steps- Thanks 1- Find a- P(Z-2.pdfPlease give an explanation and show all steps- Thanks 1- Find a- P(Z-2.pdf
Please give an explanation and show all steps- Thanks 1- Find a- P(Z-2.pdf
aathiauto
 
You are leading a central working group that encompasses representativ.pdf
You are leading a central working group that encompasses representativ.pdfYou are leading a central working group that encompasses representativ.pdf
You are leading a central working group that encompasses representativ.pdf
aathiauto
 
What type of defense is a cough reflex-A Nonspecific- secondary line o.pdf
What type of defense is a cough reflex-A Nonspecific- secondary line o.pdfWhat type of defense is a cough reflex-A Nonspecific- secondary line o.pdf
What type of defense is a cough reflex-A Nonspecific- secondary line o.pdf
aathiauto
 
Twelve jurors are randomly solected from a population of 4 milion resi.pdf
Twelve jurors are randomly solected from a population of 4 milion resi.pdfTwelve jurors are randomly solected from a population of 4 milion resi.pdf
Twelve jurors are randomly solected from a population of 4 milion resi.pdf
aathiauto
 
Use the given discrete probability distribution for the number of head.pdf
Use the given discrete probability distribution for the number of head.pdfUse the given discrete probability distribution for the number of head.pdf
Use the given discrete probability distribution for the number of head.pdf
aathiauto
 
The following graphs represent various types of cost behaviors- Graph.pdf
The following graphs represent various types of cost behaviors- Graph.pdfThe following graphs represent various types of cost behaviors- Graph.pdf
The following graphs represent various types of cost behaviors- Graph.pdf
aathiauto
 
The day after the Oscars- Blue Rose Research conducted a poll of peopl.pdf
The day after the Oscars- Blue Rose Research conducted a poll of peopl.pdfThe day after the Oscars- Blue Rose Research conducted a poll of peopl.pdf
The day after the Oscars- Blue Rose Research conducted a poll of peopl.pdf
aathiauto
 
The Barteimann Corporaton sold iss credit subsidiacy on Detnmber 31 of.pdf
The Barteimann Corporaton sold iss credit subsidiacy on Detnmber 31 of.pdfThe Barteimann Corporaton sold iss credit subsidiacy on Detnmber 31 of.pdf
The Barteimann Corporaton sold iss credit subsidiacy on Detnmber 31 of.pdf
aathiauto
 
Since World War II- national governments have focused on job growth- a.pdf
Since World War II- national governments have focused on job growth- a.pdfSince World War II- national governments have focused on job growth- a.pdf
Since World War II- national governments have focused on job growth- a.pdf
aathiauto
 
Stars on the main sequence obey a mass-luminosity relation- According.pdf
Stars on the main sequence obey a mass-luminosity relation- According.pdfStars on the main sequence obey a mass-luminosity relation- According.pdf
Stars on the main sequence obey a mass-luminosity relation- According.pdf
aathiauto
 
Health Informatics- Theoretical Foundations- and Practice Evolution- D.pdf
Health Informatics- Theoretical Foundations- and Practice Evolution- D.pdfHealth Informatics- Theoretical Foundations- and Practice Evolution- D.pdf
Health Informatics- Theoretical Foundations- and Practice Evolution- D.pdf
aathiauto
 
In what ways are national income statistics usetul-.pdf
In what ways are national income statistics usetul-.pdfIn what ways are national income statistics usetul-.pdf
In what ways are national income statistics usetul-.pdf
aathiauto
 
If a population has a standard deviation of 12- what is the VARIANCE o.pdf
If a population has a standard deviation of 12- what is the VARIANCE o.pdfIf a population has a standard deviation of 12- what is the VARIANCE o.pdf
If a population has a standard deviation of 12- what is the VARIANCE o.pdf
aathiauto
 
Given that over 97- of climate scientists agree that the climate chang.pdf
Given that over 97- of climate scientists agree that the climate chang.pdfGiven that over 97- of climate scientists agree that the climate chang.pdf
Given that over 97- of climate scientists agree that the climate chang.pdf
aathiauto
 
Given this sounding- what kind of convective event would you expect- C.pdf
Given this sounding- what kind of convective event would you expect- C.pdfGiven this sounding- what kind of convective event would you expect- C.pdf
Given this sounding- what kind of convective event would you expect- C.pdf
aathiauto
 
a- Recessions typically hurtb- What is the general trend observed amon.pdf
a- Recessions typically hurtb- What is the general trend observed amon.pdfa- Recessions typically hurtb- What is the general trend observed amon.pdf
a- Recessions typically hurtb- What is the general trend observed amon.pdf
aathiauto
 
Between 2001 and 2009-3730 adults obtained high school diplomas throug.pdf
Between 2001 and 2009-3730 adults obtained high school diplomas throug.pdfBetween 2001 and 2009-3730 adults obtained high school diplomas throug.pdf
Between 2001 and 2009-3730 adults obtained high school diplomas throug.pdf
aathiauto
 
ages -c(20-11-18-5-33).pdf
ages -c(20-11-18-5-33).pdfages -c(20-11-18-5-33).pdf
ages -c(20-11-18-5-33).pdf
aathiauto
 
1a) Which factors are involved in the movement of metals- Give a brief.pdf
1a) Which factors are involved in the movement of metals- Give a brief.pdf1a) Which factors are involved in the movement of metals- Give a brief.pdf
1a) Which factors are involved in the movement of metals- Give a brief.pdf
aathiauto
 
Ad

Recently uploaded (20)

Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18
Celine George
 
THE STG QUIZ GROUP D.pptx quiz by Ridip Hazarika
THE STG QUIZ GROUP D.pptx   quiz by Ridip HazarikaTHE STG QUIZ GROUP D.pptx   quiz by Ridip Hazarika
THE STG QUIZ GROUP D.pptx quiz by Ridip Hazarika
Ridip Hazarika
 
Kasdorf "Accessibility Essentials: A 2025 NISO Training Series, Session 5, Ac...
Kasdorf "Accessibility Essentials: A 2025 NISO Training Series, Session 5, Ac...Kasdorf "Accessibility Essentials: A 2025 NISO Training Series, Session 5, Ac...
Kasdorf "Accessibility Essentials: A 2025 NISO Training Series, Session 5, Ac...
National Information Standards Organization (NISO)
 
Debunking the Myths behind AI - v1, Carl Dalby
Debunking the Myths behind AI -  v1, Carl DalbyDebunking the Myths behind AI -  v1, Carl Dalby
Debunking the Myths behind AI - v1, Carl Dalby
Association for Project Management
 
Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
TechSoup
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
Exercise Physiology MCQS By DR. NASIR MUSTAFA
Exercise Physiology MCQS By DR. NASIR MUSTAFAExercise Physiology MCQS By DR. NASIR MUSTAFA
Exercise Physiology MCQS By DR. NASIR MUSTAFA
Dr. Nasir Mustafa
 
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
Dr. Nasir Mustafa
 
Contact Lens:::: An Overview.pptx.: Optometry
Contact Lens:::: An Overview.pptx.: OptometryContact Lens:::: An Overview.pptx.: Optometry
Contact Lens:::: An Overview.pptx.: Optometry
MushahidRaza8
 
"Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules""Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules"
rupalinirmalbpharm
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
APM Midlands Region April 2025 Sacha Hind Circulated.pdf
APM Midlands Region April 2025 Sacha Hind Circulated.pdfAPM Midlands Region April 2025 Sacha Hind Circulated.pdf
APM Midlands Region April 2025 Sacha Hind Circulated.pdf
Association for Project Management
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
How to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POSHow to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POS
Celine George
 
To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18
Celine George
 
THE STG QUIZ GROUP D.pptx quiz by Ridip Hazarika
THE STG QUIZ GROUP D.pptx   quiz by Ridip HazarikaTHE STG QUIZ GROUP D.pptx   quiz by Ridip Hazarika
THE STG QUIZ GROUP D.pptx quiz by Ridip Hazarika
Ridip Hazarika
 
Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
TechSoup
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
Exercise Physiology MCQS By DR. NASIR MUSTAFA
Exercise Physiology MCQS By DR. NASIR MUSTAFAExercise Physiology MCQS By DR. NASIR MUSTAFA
Exercise Physiology MCQS By DR. NASIR MUSTAFA
Dr. Nasir Mustafa
 
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
Dr. Nasir Mustafa
 
Contact Lens:::: An Overview.pptx.: Optometry
Contact Lens:::: An Overview.pptx.: OptometryContact Lens:::: An Overview.pptx.: Optometry
Contact Lens:::: An Overview.pptx.: Optometry
MushahidRaza8
 
"Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules""Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules"
rupalinirmalbpharm
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
How to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POSHow to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POS
Celine George
 
To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
Ad

DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf

  • 1. DoublyList.cpp: #include "DoublyList.h" using namespace std; void DoublyList::insertFront(int newData) { if (first == nullptr) { first = new DLLNode(newData, nullptr, nullptr); last = first; // Common error: Forgetting to reset pointer last. } else { first = new DLLNode(newData, nullptr, first); first->getNext()->setPrev(first); // Common error: Forgetting to connect pointer // prev of what is now the second node to the // new first node. } ++count; } void DoublyList::printForward() const { DLLNode* current = first; while (current != nullptr) { cout << current->getData() << " "; current = current->getNext(); } } void DoublyList::printReverse() const { DLLNode* current = last; while (current != nullptr) { cout << current->getData() << " "; current = current->getPrev(); } }
  • 2. void DoublyList::clearList() { DLLNode* temp = first; while (first != nullptr) { first = first->getNext(); delete temp; temp = first; } last = nullptr; // Don't forget to reset pointer last to nullptr. count = 0; } DoublyList::~DoublyList() { if (first != nullptr) clearList(); } DoublyList.h #ifndef DOUBLYLIST_H #define DOUBLYLIST_H #include <string> #include <iostream> class DLLNode { public: DLLNode() : data(0), prev(nullptr), next(nullptr) {} DLLNode(int theData, DLLNode* prevLink, DLLNode* nextLink) : data(theData), prev(prevLink), next(nextLink) {} int getData() const { return data; } DLLNode* getPrev() const { return prev; } DLLNode* getNext() const { return next; } void setData(int theData) { data = theData; } void setPrev(DLLNode* prevLink) { prev = prevLink; } void setNext(DLLNode* nextLink) { next = nextLink; } ~DLLNode(){} private: int data; // To simplify, we are using only one piece of data. DLLNode* prev;
  • 3. DLLNode* next; }; class DoublyList { public: DoublyList() : first(nullptr), last(nullptr), count(0) {} void insertFront(int newData); void printForward() const; void printReverse() const; void rotateNodesRight(int); void clearList(); ~DoublyList(); private: // Pointer to the first node in the list. DLLNode*first; // Pointer to the last node in the list. DLLNode*last; // Number of nodes in the list. int count; }; #endif Main.cpp #include "DoublyList.h" #include <iostream> #include <vector> using namespace std; int main() { vector<vector<int>> data = { {25, 76, 35, 67, 15, 98}, {1, 2, 3, 4, 5, 6, 7, 8, 9}, {10, 20}, {34, 56, 78, 12, 89, 34, 76, 28, 54, 22, 41}, {123, 873, 619},
  • 4. }; vector<int> nodesToRotate = { 2, 3, 1, 9, 2 }; { DoublyList doublyList; int vectorSize = static_cast<int>(data.size()); for (int i = 0; i < vectorSize; ++i) { int innerSize = static_cast<int>(data[i].size()); for (int j = innerSize - 1; j >= 0; --j) doublyList.insertFront(data[i].at(j)); cout << "Rotate right: " << nodesToRotate[i] << "n"; cout << " List is: "; doublyList.printForward(); cout << "n"; doublyList.rotateNodesRight(nodesToRotate[i]); cout << "After rotating:"; cout << "n Print forward: "; doublyList.printForward(); cout << "nPrint backwards: "; doublyList.printReverse(); cout << "nn"; doublyList.clearList(); } } cout << "n"; system("Pause"); return 0; Function rotateNodesRight() - This function is a member function of the class DoublyList. - Parameter: An int that stores the number of times that the rotation occurs. - The function works as the previous one, with the difference that the rotation occurs to the right. Again, this is about resetting pointers, not about moving data. - Example Page 4 of 5 List is: 257635671598 Parameter is: 2 After rotating, list is: 15 98 25 76 35 67 - Assumptions - The list has at least 2 elements. - The parameter is always smaller than the number of elements in the list. - Restrictions: - Cannot create helper functions.