SlideShare a Scribd company logo
1 of 7
Download to read offline
// for initializer_list
#include <initializer_list>
// for ostream
#include <iostream>
// for bidirectional_iterator_tag, prev, next, distance
#include <iterator>
// for ptrdiff_t, size_t, swap
#include <utility>
/************************************************************/
// struct representing our ListNode
//
// contains three data members:
// - data
// - next
// - prev
template<typename T>
struct ListNode
{
ListNode () : data ()
{
}
ListNode (const T& v) : data (v)
{
}
ListNode (const T& v, ListNode* n, ListNode* p) : data (v), next (n), prev (p)
{
}
// unhooks the range [begin,end] from a linked list
// NOTE: will lose reference to begin and end if you
// are not keeping track of it!
//
// - does not create any new nodes
// - does not destroy any existing nodes
// - begin is start of range to remove
// - end is inclusive end of range to remove
//
// [5]
static void
unhook_range (ListNode* begin, ListNode* end)
{
if (begin == nullptr || end == nullptr)
{
return;
}
if (begin == end)
{
return;
}
if (begin->prev != nullptr)
{
begin->prev->next = end->next;
}
if (end->next != nullptr)
{
end->next->prev = begin->prev;
}
begin->prev = nullptr;
end->next = nullptr;
}
// inserts the range [first,last] before this
// NOTE: does not create any new nodes, does not destroy any existing nodes
//
// [5]
void
hook_range (ListNode* first, ListNode* last)
{
if (first == nullptr || last == nullptr)
{
return;
}
unhook();
if (first == last)
{
first->prev = this;
last->next = this;
next = first;
prev = last;
} else
{
ListNode* before_first = first->prev;
ListNode* after_last = last->next;
before_first->next = first;
first->prev = before_first;
last->next = after_last;
after_last->prev = last;
next = first;
prev = last;
}
}
// insert first before this
void
hook (ListNode* first)
{
hook_range (first, first);
}
// unhooks current node from linked list
void
unhook ()
{
ListNode::unhook_range (this, this);
}
T data;
ListNode* next{nullptr};
ListNode* prev{nullptr};
};
/************************************************************/
// Struct representing a List const_iterator
//
// contains a single data member:
// - m_nodePtr
template<typename T>
struct ListConstIterator
{
using value_type = T;
using pointer = const value_type*;
using reference = const value_type&;
using difference_type = std::ptrdiff_t;
using iterator_category = std::bidirectional_iterator_tag;
using Node = const ListNode<value_type>;
public:
// construct from Node
ListConstIterator (Node* n) : m_nodePtr (n)
{
}
// construct from Iterator
ListConstIterator (const ListIterator<T>& i) : m_nodePtr (i.m_nodePtr)
{
}
// iterator dereference
reference operator* () const
{
return m_nodePtr->data;
}
// iterator member access
pointer operator-> () const
{
return &(m_nodePtr->data);
}
// pre-increment
ListConstIterator&
operator++ ()
{
m_nodePtr = m_nodePtr->next;
return *this;
}
// post-increment
// [2]
ListConstIterator
operator++ (int)
{
// TODO
}
// pre-decrement
// [2]
ListConstIterator&
operator-- ()
{
// TODO
}
// post-decrement
ListConstIterator
operator-- (int)
{
ListConstIterator copy (*this);
m_nodePtr = m_nodePtr->prev;
return copy;
}
friend bool operator==
<> (const ListConstIterator& i, const ListConstIterator& j);
friend bool operator!=
<> (const ListConstIterator& i, const ListConstIterator& j);
private:
Node* m_nodePtr{nullptr};
friend class List<T>;
friend class ListIterator<T>;
};
template<typename T>
bool
operator== (const ListConstIterator<T>& i, const ListConstIterator<T>& j)
{
return i.m_nodePtr == j.m_nodePtr;
}
// compares the underlying pointers for equality
// [2]
template<typename T>
bool
operator!= (const ListConstIterator<T>& i, const ListConstIterator<T>& j)
{
// TODO -- be sure to not accidently make this an infinite recursive call!
}
/************************************************************/
// Struct representing a List iterator
//
// contains a single data member:
// - m_nodePtr
template<typename T>
struct ListIterator
{
using value_type = T;
using pointer = value_type*;
using reference = value_type&;
using difference_type = std::ptrdiff_t;
using iterator_category = std::bidirectional_iterator_tag;
using Node = ListNode<value_type>;
public:
// construct from Node
ListIterator (Node* n) : m_nodePtr (n)
{
}
reference operator* () const
{
return m_nodePtr->data;
}
pointer operator-> () const
{
return &(m_nodePtr->data);
}
// advances to the "next" pointer, returns reference to self
// [2]
ListIterator&
operator++ ()
{
// TODO
}
// advances to the "next" pointer, returns copy of self prior to advancement
ListIterator
operator++ (int)
{
ListIterator copy (*this);
m_nodePtr = m_nodePtr->next;
return copy;
}
// advances to the "prev" pointer, returns reference to self
ListIterator&
operator-- ()
{
m_nodePtr = m_nodePtr->prev;
return *this;
}
// advances to the "prev" pointer, returns copy of self prior to advancement
// [2]
ListIterator
operator-- (int)
{
// TODO
}
friend bool operator==<> (const ListIterator& i, const ListIterator& j);
friend bool operator!=<> (const ListIterator& i, const ListIterator& j);
private:
Node* m_nodePtr{nullptr};
friend class List<T>;
friend class ListConstIterator<T>;
};
// compares the underlying pointers for equality
// [2]
template<typename T>
bool
operator== (const ListIterator<T>& i, const ListIterator<T>& j)
{
// TODO -- be sure to not accidently make this an infinite recursive call!
}
template<typename T>
bool
operator!= (const ListIterator<T>& i, const ListIterator<T>& j)
{
return i.m_nodePtr != j.m_nodePtr;
}
Please complete the implementation for the missing parts marked TODO!

More Related Content

Similar to for initializer_list include ltinitializer_listgt .pdf

Program 8 C++newproblems.txt12333142013KristinBrewer1032823.docx
Program 8 C++newproblems.txt12333142013KristinBrewer1032823.docxProgram 8 C++newproblems.txt12333142013KristinBrewer1032823.docx
Program 8 C++newproblems.txt12333142013KristinBrewer1032823.docx
wkyra78
 
Below is a depiction of a doubly-linked list implementation of the bag.docx
Below is a depiction of a doubly-linked list implementation of the bag.docxBelow is a depiction of a doubly-linked list implementation of the bag.docx
Below is a depiction of a doubly-linked list implementation of the bag.docx
gilliandunce53776
 
I have the following code and I need to know why I am receiving the .pdf
I have the following code and I need to know why I am receiving the .pdfI have the following code and I need to know why I am receiving the .pdf
I have the following code and I need to know why I am receiving the .pdf
ezzi552
 
In this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdfIn this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdf
contact41
 
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdfC++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
callawaycorb73779
 
include ltfunctionalgt include ltiteratorgt inclu.pdf
include ltfunctionalgt include ltiteratorgt inclu.pdfinclude ltfunctionalgt include ltiteratorgt inclu.pdf
include ltfunctionalgt include ltiteratorgt inclu.pdf
aathmiboutique
 
Use C++ Write a function to merge two doubly linked lists. The input.pdf
Use C++ Write a function to merge two doubly linked lists. The input.pdfUse C++ Write a function to merge two doubly linked lists. The input.pdf
Use C++ Write a function to merge two doubly linked lists. The input.pdf
shalins6
 
How do I fix it in LinkedList.javaLinkedList.java Define.pdf
How do I fix it in LinkedList.javaLinkedList.java Define.pdfHow do I fix it in LinkedList.javaLinkedList.java Define.pdf
How do I fix it in LinkedList.javaLinkedList.java Define.pdf
mail931892
 
Please code in C++ and do only the �TO DO�s and all of them. There a.pdf
Please code in C++ and do only the �TO DO�s and all of them. There a.pdfPlease code in C++ and do only the �TO DO�s and all of them. There a.pdf
Please code in C++ and do only the �TO DO�s and all of them. There a.pdf
farankureshi
 
Complete in JavaCardApp.javapublic class CardApp { private.pdf
Complete in JavaCardApp.javapublic class CardApp {   private.pdfComplete in JavaCardApp.javapublic class CardApp {   private.pdf
Complete in JavaCardApp.javapublic class CardApp { private.pdf
MAYANKBANSAL1981
 
How do I fix it in javaLinkedList.java Defines a doubl.pdf
How do I fix it in javaLinkedList.java Defines a doubl.pdfHow do I fix it in javaLinkedList.java Defines a doubl.pdf
How do I fix it in javaLinkedList.java Defines a doubl.pdf
fmac5
 
Please read the comment ins codeExpressionTree.java-------------.pdf
Please read the comment ins codeExpressionTree.java-------------.pdfPlease read the comment ins codeExpressionTree.java-------------.pdf
Please read the comment ins codeExpressionTree.java-------------.pdf
shanki7
 
Getting the following errorsError 1 error C2436 {ctor} mem.pdf
Getting the following errorsError 1 error C2436 {ctor}  mem.pdfGetting the following errorsError 1 error C2436 {ctor}  mem.pdf
Getting the following errorsError 1 error C2436 {ctor} mem.pdf
herminaherman
 
Please complete ALL of the �TO DO�s in this code. I am really strugg.pdf
Please complete ALL of the �TO DO�s in this code. I am really strugg.pdfPlease complete ALL of the �TO DO�s in this code. I am really strugg.pdf
Please complete ALL of the �TO DO�s in this code. I am really strugg.pdf
support58
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfThis assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdf
EricvtJFraserr
 
I need help completing this C++ code with these requirements.instr.pdf
I need help completing this C++ code with these requirements.instr.pdfI need help completing this C++ code with these requirements.instr.pdf
I need help completing this C++ code with these requirements.instr.pdf
eyeonsecuritysystems
 
Need Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdf
Need Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdfNeed Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdf
Need Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdf
Edwardw5nSlaterl
 
Merge Sort implementation in C++ The implementation for Mergesort gi.pdf
Merge Sort implementation in C++ The implementation for Mergesort gi.pdfMerge Sort implementation in C++ The implementation for Mergesort gi.pdf
Merge Sort implementation in C++ The implementation for Mergesort gi.pdf
mdameer02
 

Similar to for initializer_list include ltinitializer_listgt .pdf (20)

Program 8 C++newproblems.txt12333142013KristinBrewer1032823.docx
Program 8 C++newproblems.txt12333142013KristinBrewer1032823.docxProgram 8 C++newproblems.txt12333142013KristinBrewer1032823.docx
Program 8 C++newproblems.txt12333142013KristinBrewer1032823.docx
 
Below is a depiction of a doubly-linked list implementation of the bag.docx
Below is a depiction of a doubly-linked list implementation of the bag.docxBelow is a depiction of a doubly-linked list implementation of the bag.docx
Below is a depiction of a doubly-linked list implementation of the bag.docx
 
I have the following code and I need to know why I am receiving the .pdf
I have the following code and I need to know why I am receiving the .pdfI have the following code and I need to know why I am receiving the .pdf
I have the following code and I need to know why I am receiving the .pdf
 
In this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdfIn this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdf
 
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdfC++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
 
include ltfunctionalgt include ltiteratorgt inclu.pdf
include ltfunctionalgt include ltiteratorgt inclu.pdfinclude ltfunctionalgt include ltiteratorgt inclu.pdf
include ltfunctionalgt include ltiteratorgt inclu.pdf
 
Use C++ Write a function to merge two doubly linked lists. The input.pdf
Use C++ Write a function to merge two doubly linked lists. The input.pdfUse C++ Write a function to merge two doubly linked lists. The input.pdf
Use C++ Write a function to merge two doubly linked lists. The input.pdf
 
How do I fix it in LinkedList.javaLinkedList.java Define.pdf
How do I fix it in LinkedList.javaLinkedList.java Define.pdfHow do I fix it in LinkedList.javaLinkedList.java Define.pdf
How do I fix it in LinkedList.javaLinkedList.java Define.pdf
 
Please code in C++ and do only the �TO DO�s and all of them. There a.pdf
Please code in C++ and do only the �TO DO�s and all of them. There a.pdfPlease code in C++ and do only the �TO DO�s and all of them. There a.pdf
Please code in C++ and do only the �TO DO�s and all of them. There a.pdf
 
Complete in JavaCardApp.javapublic class CardApp { private.pdf
Complete in JavaCardApp.javapublic class CardApp {   private.pdfComplete in JavaCardApp.javapublic class CardApp {   private.pdf
Complete in JavaCardApp.javapublic class CardApp { private.pdf
 
How do I fix it in javaLinkedList.java Defines a doubl.pdf
How do I fix it in javaLinkedList.java Defines a doubl.pdfHow do I fix it in javaLinkedList.java Defines a doubl.pdf
How do I fix it in javaLinkedList.java Defines a doubl.pdf
 
This class maintains a list of 4 integers. This list .docx
 This class maintains a list of 4 integers.   This list .docx This class maintains a list of 4 integers.   This list .docx
This class maintains a list of 4 integers. This list .docx
 
Please read the comment ins codeExpressionTree.java-------------.pdf
Please read the comment ins codeExpressionTree.java-------------.pdfPlease read the comment ins codeExpressionTree.java-------------.pdf
Please read the comment ins codeExpressionTree.java-------------.pdf
 
Getting the following errorsError 1 error C2436 {ctor} mem.pdf
Getting the following errorsError 1 error C2436 {ctor}  mem.pdfGetting the following errorsError 1 error C2436 {ctor}  mem.pdf
Getting the following errorsError 1 error C2436 {ctor} mem.pdf
 
Please complete ALL of the �TO DO�s in this code. I am really strugg.pdf
Please complete ALL of the �TO DO�s in this code. I am really strugg.pdfPlease complete ALL of the �TO DO�s in this code. I am really strugg.pdf
Please complete ALL of the �TO DO�s in this code. I am really strugg.pdf
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfThis assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdf
 
C++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docxC++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docx
 
I need help completing this C++ code with these requirements.instr.pdf
I need help completing this C++ code with these requirements.instr.pdfI need help completing this C++ code with these requirements.instr.pdf
I need help completing this C++ code with these requirements.instr.pdf
 
Need Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdf
Need Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdfNeed Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdf
Need Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdf
 
Merge Sort implementation in C++ The implementation for Mergesort gi.pdf
Merge Sort implementation in C++ The implementation for Mergesort gi.pdfMerge Sort implementation in C++ The implementation for Mergesort gi.pdf
Merge Sort implementation in C++ The implementation for Mergesort gi.pdf
 

More from ajay1317

The lemonade stands are perfectly competitive because A t.pdf
 The lemonade stands are perfectly competitive because A t.pdf The lemonade stands are perfectly competitive because A t.pdf
The lemonade stands are perfectly competitive because A t.pdf
ajay1317
 
Table Region .pdf
 Table Region  .pdf Table Region  .pdf
Table Region .pdf
ajay1317
 

More from ajay1317 (20)

0 Suppose that a subsidy plan is introduced for lowincome .pdf
0 Suppose that a subsidy plan is introduced for lowincome .pdf0 Suppose that a subsidy plan is introduced for lowincome .pdf
0 Suppose that a subsidy plan is introduced for lowincome .pdf
 
+ 1D 1W1M3M1Y5Y Your position Shares Market value 15 145.pdf
+ 1D 1W1M3M1Y5Y Your position Shares Market value 15 145.pdf+ 1D 1W1M3M1Y5Y Your position Shares Market value 15 145.pdf
+ 1D 1W1M3M1Y5Y Your position Shares Market value 15 145.pdf
 
proxyc CSAPP Web proxy NAME IMPORTANT Giv.pdf
  proxyc  CSAPP Web proxy   NAME    IMPORTANT Giv.pdf  proxyc  CSAPP Web proxy   NAME    IMPORTANT Giv.pdf
proxyc CSAPP Web proxy NAME IMPORTANT Giv.pdf
 
AIDS is a diagnostic term applied to HIVinfected persons .pdf
 AIDS is a diagnostic term applied to HIVinfected persons .pdf AIDS is a diagnostic term applied to HIVinfected persons .pdf
AIDS is a diagnostic term applied to HIVinfected persons .pdf
 
Three Theories of DNA Replication Who were the two scien.pdf
 Three Theories of DNA Replication  Who were the two scien.pdf Three Theories of DNA Replication  Who were the two scien.pdf
Three Theories of DNA Replication Who were the two scien.pdf
 
The lemonade stands are perfectly competitive because A t.pdf
 The lemonade stands are perfectly competitive because A t.pdf The lemonade stands are perfectly competitive because A t.pdf
The lemonade stands are perfectly competitive because A t.pdf
 
This program reads a decimal array and outputs each numb.pdf
 This program reads a decimal array and outputs each  numb.pdf This program reads a decimal array and outputs each  numb.pdf
This program reads a decimal array and outputs each numb.pdf
 
Two novice business students come to their professor and a.pdf
 Two novice business students come to their professor and a.pdf Two novice business students come to their professor and a.pdf
Two novice business students come to their professor and a.pdf
 
Un mtodo operativo para administrar el inventario es la i.pdf
 Un mtodo operativo para administrar el inventario es la i.pdf Un mtodo operativo para administrar el inventario es la i.pdf
Un mtodo operativo para administrar el inventario es la i.pdf
 
Table Region .pdf
 Table Region  .pdf Table Region  .pdf
Table Region .pdf
 
Supongamos que la Tierra gir hacia atrs pero an orbita.pdf
 Supongamos que la Tierra gir hacia atrs pero an orbita.pdf Supongamos que la Tierra gir hacia atrs pero an orbita.pdf
Supongamos que la Tierra gir hacia atrs pero an orbita.pdf
 
Synthesizes the new DNA strands in the 5 3 direction .pdf
 Synthesizes the new DNA strands in the 5 3 direction  .pdf Synthesizes the new DNA strands in the 5 3 direction  .pdf
Synthesizes the new DNA strands in the 5 3 direction .pdf
 
returns a new copy of the LinkedList It creates a copy .pdf
 returns a new copy of the LinkedList It creates a copy .pdf returns a new copy of the LinkedList It creates a copy .pdf
returns a new copy of the LinkedList It creates a copy .pdf
 
Sony Ericsson is a global company that was established in .pdf
 Sony Ericsson is a global company that was established in .pdf Sony Ericsson is a global company that was established in .pdf
Sony Ericsson is a global company that was established in .pdf
 
11 ST segment depression may indicate Ischemia Normal fin.pdf
 11 ST segment depression may indicate Ischemia Normal fin.pdf 11 ST segment depression may indicate Ischemia Normal fin.pdf
11 ST segment depression may indicate Ischemia Normal fin.pdf
 
Realice una investigacin adicional para obtener ms infor.pdf
 Realice una investigacin adicional para obtener ms infor.pdf Realice una investigacin adicional para obtener ms infor.pdf
Realice una investigacin adicional para obtener ms infor.pdf
 
Elvira es una pintora abstracta con un talento increble p.pdf
 Elvira es una pintora abstracta con un talento increble p.pdf Elvira es una pintora abstracta con un talento increble p.pdf
Elvira es una pintora abstracta con un talento increble p.pdf
 
Programming Assignment 4 Calculate the first 16 Fib.pdf
 Programming Assignment 4  Calculate the first 16 Fib.pdf Programming Assignment 4  Calculate the first 16 Fib.pdf
Programming Assignment 4 Calculate the first 16 Fib.pdf
 
El sndrome X frgil es un trastorno dominante ligado al s.pdf
 El sndrome X frgil es un trastorno dominante ligado al s.pdf El sndrome X frgil es un trastorno dominante ligado al s.pdf
El sndrome X frgil es un trastorno dominante ligado al s.pdf
 
In grading eggs into small medium and large the Nancy F.pdf
 In grading eggs into small medium and large the Nancy F.pdf In grading eggs into small medium and large the Nancy F.pdf
In grading eggs into small medium and large the Nancy F.pdf
 

Recently uploaded

Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
EADTU
 

Recently uploaded (20)

How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
Play hard learn harder: The Serious Business of Play
Play hard learn harder:  The Serious Business of PlayPlay hard learn harder:  The Serious Business of Play
Play hard learn harder: The Serious Business of Play
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learning
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Economic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food AdditivesEconomic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food Additives
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf arts
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 

for initializer_list include ltinitializer_listgt .pdf

  • 1. // for initializer_list #include <initializer_list> // for ostream #include <iostream> // for bidirectional_iterator_tag, prev, next, distance #include <iterator> // for ptrdiff_t, size_t, swap #include <utility> /************************************************************/ // struct representing our ListNode // // contains three data members: // - data // - next // - prev template<typename T> struct ListNode { ListNode () : data () { } ListNode (const T& v) : data (v) { } ListNode (const T& v, ListNode* n, ListNode* p) : data (v), next (n), prev (p) { } // unhooks the range [begin,end] from a linked list // NOTE: will lose reference to begin and end if you // are not keeping track of it! // // - does not create any new nodes // - does not destroy any existing nodes // - begin is start of range to remove // - end is inclusive end of range to remove // // [5] static void unhook_range (ListNode* begin, ListNode* end) { if (begin == nullptr || end == nullptr) {
  • 2. return; } if (begin == end) { return; } if (begin->prev != nullptr) { begin->prev->next = end->next; } if (end->next != nullptr) { end->next->prev = begin->prev; } begin->prev = nullptr; end->next = nullptr; } // inserts the range [first,last] before this // NOTE: does not create any new nodes, does not destroy any existing nodes // // [5] void hook_range (ListNode* first, ListNode* last) { if (first == nullptr || last == nullptr) { return; } unhook(); if (first == last) { first->prev = this; last->next = this; next = first; prev = last; } else { ListNode* before_first = first->prev; ListNode* after_last = last->next; before_first->next = first; first->prev = before_first; last->next = after_last;
  • 3. after_last->prev = last; next = first; prev = last; } } // insert first before this void hook (ListNode* first) { hook_range (first, first); } // unhooks current node from linked list void unhook () { ListNode::unhook_range (this, this); } T data; ListNode* next{nullptr}; ListNode* prev{nullptr}; }; /************************************************************/ // Struct representing a List const_iterator // // contains a single data member: // - m_nodePtr template<typename T> struct ListConstIterator { using value_type = T; using pointer = const value_type*; using reference = const value_type&; using difference_type = std::ptrdiff_t; using iterator_category = std::bidirectional_iterator_tag; using Node = const ListNode<value_type>; public: // construct from Node ListConstIterator (Node* n) : m_nodePtr (n) { } // construct from Iterator ListConstIterator (const ListIterator<T>& i) : m_nodePtr (i.m_nodePtr)
  • 4. { } // iterator dereference reference operator* () const { return m_nodePtr->data; } // iterator member access pointer operator-> () const { return &(m_nodePtr->data); } // pre-increment ListConstIterator& operator++ () { m_nodePtr = m_nodePtr->next; return *this; } // post-increment // [2] ListConstIterator operator++ (int) { // TODO } // pre-decrement // [2] ListConstIterator& operator-- () { // TODO } // post-decrement ListConstIterator operator-- (int) { ListConstIterator copy (*this); m_nodePtr = m_nodePtr->prev; return copy; } friend bool operator==
  • 5. <> (const ListConstIterator& i, const ListConstIterator& j); friend bool operator!= <> (const ListConstIterator& i, const ListConstIterator& j); private: Node* m_nodePtr{nullptr}; friend class List<T>; friend class ListIterator<T>; }; template<typename T> bool operator== (const ListConstIterator<T>& i, const ListConstIterator<T>& j) { return i.m_nodePtr == j.m_nodePtr; } // compares the underlying pointers for equality // [2] template<typename T> bool operator!= (const ListConstIterator<T>& i, const ListConstIterator<T>& j) { // TODO -- be sure to not accidently make this an infinite recursive call! } /************************************************************/ // Struct representing a List iterator // // contains a single data member: // - m_nodePtr template<typename T> struct ListIterator { using value_type = T; using pointer = value_type*; using reference = value_type&; using difference_type = std::ptrdiff_t; using iterator_category = std::bidirectional_iterator_tag; using Node = ListNode<value_type>; public: // construct from Node ListIterator (Node* n) : m_nodePtr (n) { } reference operator* () const
  • 6. { return m_nodePtr->data; } pointer operator-> () const { return &(m_nodePtr->data); } // advances to the "next" pointer, returns reference to self // [2] ListIterator& operator++ () { // TODO } // advances to the "next" pointer, returns copy of self prior to advancement ListIterator operator++ (int) { ListIterator copy (*this); m_nodePtr = m_nodePtr->next; return copy; } // advances to the "prev" pointer, returns reference to self ListIterator& operator-- () { m_nodePtr = m_nodePtr->prev; return *this; } // advances to the "prev" pointer, returns copy of self prior to advancement // [2] ListIterator operator-- (int) { // TODO } friend bool operator==<> (const ListIterator& i, const ListIterator& j); friend bool operator!=<> (const ListIterator& i, const ListIterator& j); private: Node* m_nodePtr{nullptr}; friend class List<T>; friend class ListConstIterator<T>;
  • 7. }; // compares the underlying pointers for equality // [2] template<typename T> bool operator== (const ListIterator<T>& i, const ListIterator<T>& j) { // TODO -- be sure to not accidently make this an infinite recursive call! } template<typename T> bool operator!= (const ListIterator<T>& i, const ListIterator<T>& j) { return i.m_nodePtr != j.m_nodePtr; } Please complete the implementation for the missing parts marked TODO!