SlideShare a Scribd company logo
1 of 4
You are required to implement the following functions for doubly linked lists.
Note that code for creating a doubly linked list from an array of values is given to you, as well as
testing code (driver program) to make sure that all functions work as expected.
1. find: Returns true if the given value is found in the list, and false otherwise.
template <typename Object>
bool findInDLL(DoubleNode<Object>* head, Object value);
2. insertBefore: Finds a given value and inserts a new node before it with a new value. Returns
true if the insertion is successful, else false.
template <typename Object>
bool insertBeforeDLL(DoubleNode<Object>*& head, Object value, Object newValue);
3. erase: Finds a given value and deletes the matching node from the linked list. Returns true if
the insertion is successful, else false.
template <typename Object>
bool eraseInDLL(DoubleNode<Object>*& head, Object value);
Sample output:
Printing Double linked list:
1 2 4 7 6 8
Finding 7 in the List:
7 exist in the list
Inserting 3 before 4 :
1 2 3 4 7 6 8
Inserting 0 before 1 (inserting at the start of the list):
0 1 2 3 4 7 6 8
Deleting 3:
0 1 2 4 7 6 8
Deleting 8 (deleting last element in the list):
0 1 2 4 7 6
Deleting 0 (deleting first element in the list):
1 2 4 7 6
Deleting -99 (trying to delete an element which is not present in the list):
Value not Found!
GIVEN THE C++ TEMPLATE PROGRAM
#include <iostream>
#include <string>
using namespace std;
//Doubly Linked List structure
template <typename Object>
struct DoubleNode
{
Object data;
DoubleNode *prev;
DoubleNode *next;
DoubleNode(const Object & d = Object{}, DoubleNode * p = nullptr, DoubleNode * n = nullptr)
: data{ d }, prev{ p }, next{ n } { }
};
//function to create Doubly Linked List with values
template <typename Object>
DoubleNode<Object>* createDLL(Object ary[], int size)
{
DoubleNode<Object>* first = new DoubleNode<Object>(ary[0]);
DoubleNode<Object>* temp = first;
for (int i = 1; i < size; i++)
{
DoubleNode<Object>* node = new DoubleNode<Object>(ary[i]);
temp->next = node;
node->prev = temp;
temp = node;
}
return first;
}
template <typename Object>
void printDLL(DoubleNode<Object>* head)
{
while (head != nullptr)
{
cout << head->data << "t";
head = head->next;
}
cout << endl;
}
template <typename Object>
bool findInDLL(DoubleNode<Object>* head, Object value)
{
//your code goes here
}
template <typename Object>
bool insertBeforeDLL(DoubleNode<Object>* & head, Object givenValue, Object newValue) {
DoubleNode<Object> *newNode = new DoubleNode<Object>(newValue);
//your code goes here
}
template <typename Object>
bool eraseInDLL(DoubleNode<Object>*& head, Object givenValue) {
DoubleNode<Object> *temp = head;
//your code goes here
}
int main()
{
int ary[] = { 1,2,4,7,6,8 }, size = 6;
DoubleNode<int>* head = createDLL<int>(ary, size);
cout << "Printing Double linked list: n";
printDLL(head);
cout << "nFinding 7 in the List: n";
if (findInDLL(head, 7))
cout << "7 exist in the listn";
//Testing insertBefore function
cout << "nInserting 3 before 4 :n";
bool success = insertBeforeDLL(head, 4, 3);
if (success)
printDLL(head);
else
cout << "Value not Found! n";
cout << "nInserting 0 before 1 (inserting at the start of the list):n";
success = insertBeforeDLL(head, 1, 0);
if (success)
printDLL(head);
else
cout << "Value not Found! n";
cout << "nDeleting 3:n ";
success = eraseInDLL(head, 3);
if (success)
printDLL(head);
else
cout << "Value not Found! n";
cout << "nDeleting 8 (deleting last element in the list):n ";
success = eraseInDLL(head, 8);
if (success)
printDLL(head);
else
cout << "Value not Found! n";
cout << "nDeleting 0 (deleting first element in the list):n ";
success = eraseInDLL(head, 0);
if (success)
printDLL(head);
else
cout << "Value not Found! n";
cout << "nDeleting -99 (trying to delete an element which is not present in the list):n ";
success = eraseInDLL(head, -99);
if (success)
printDLL(head);
else
cout << "Value not Found! n";
return 0;
}

More Related Content

Similar to You are required to implement the following functions for doubly linke.docx

Sorted number list implementation with linked listsStep 1 Inspec.pdf
 Sorted number list implementation with linked listsStep 1 Inspec.pdf Sorted number list implementation with linked listsStep 1 Inspec.pdf
Sorted number list implementation with linked listsStep 1 Inspec.pdfalmaniaeyewear
 
Lab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docxLab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docxteyaj1
 
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdfInspect the class declaration for a doubly-linked list node in Node-h-.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdfvishalateen
 
implement the ListLinked ADT (the declaration is given in ListLinked.pdf
implement the ListLinked ADT (the declaration is given in ListLinked.pdfimplement the ListLinked ADT (the declaration is given in ListLinked.pdf
implement the ListLinked ADT (the declaration is given in ListLinked.pdfFOREVERPRODUCTCHD
 
Object Oriented Programming Using C++: C++ STL Programming.pptx
Object Oriented Programming Using C++: C++ STL Programming.pptxObject Oriented Programming Using C++: C++ STL Programming.pptx
Object Oriented Programming Using C++: C++ STL Programming.pptxRashidFaridChishti
 
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdfDoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdfaathiauto
 
Write a program to find the number of comparisons using the binary se.docx
 Write a program to find the number of comparisons using the binary se.docx Write a program to find the number of comparisons using the binary se.docx
Write a program to find the number of comparisons using the binary se.docxajoy21
 
Please need help on following program using c++ language. Please inc.pdf
Please need help on following program using c++ language. Please inc.pdfPlease need help on following program using c++ language. Please inc.pdf
Please need help on following program using c++ language. Please inc.pdfnitinarora01
 
Need to be done in C++ Please Sorted number list implementation wit.pdf
Need to be done in C++  Please   Sorted number list implementation wit.pdfNeed to be done in C++  Please   Sorted number list implementation wit.pdf
Need to be done in C++ Please Sorted number list implementation wit.pdfaathiauto
 
In C++ please, do not alter node.hStep 1 Inspect the Node.h file.pdf
In C++ please, do not alter node.hStep 1 Inspect the Node.h file.pdfIn C++ please, do not alter node.hStep 1 Inspect the Node.h file.pdf
In C++ please, do not alter node.hStep 1 Inspect the Node.h file.pdfstopgolook
 
10- Consider the following data structure used for implementing a link.docx
10- Consider the following data structure used for implementing a link.docx10- Consider the following data structure used for implementing a link.docx
10- Consider the following data structure used for implementing a link.docxtodd991
 
Need to be done in C Please Sorted number list implementation with.pdf
Need to be done in C  Please   Sorted number list implementation with.pdfNeed to be done in C  Please   Sorted number list implementation with.pdf
Need to be done in C Please Sorted number list implementation with.pdfaathmaproducts
 
Please help solve this in C++ So the program is working fin.pdf
Please help solve this in C++ So the program is working fin.pdfPlease help solve this in C++ So the program is working fin.pdf
Please help solve this in C++ So the program is working fin.pdfankit11134
 
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfHow do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfmail931892
 
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdfTHE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdffathimahardwareelect
 
I need help with this code working Create another project and add yo.pdf
I need help with this code working Create another project and add yo.pdfI need help with this code working Create another project and add yo.pdf
I need help with this code working Create another project and add yo.pdffantoosh1
 
Use the following data set that compares age to average years lef.docx
Use the following data set that compares age to average years lef.docxUse the following data set that compares age to average years lef.docx
Use the following data set that compares age to average years lef.docxdickonsondorris
 

Similar to You are required to implement the following functions for doubly linke.docx (20)

Sorted number list implementation with linked listsStep 1 Inspec.pdf
 Sorted number list implementation with linked listsStep 1 Inspec.pdf Sorted number list implementation with linked listsStep 1 Inspec.pdf
Sorted number list implementation with linked listsStep 1 Inspec.pdf
 
dynamicList.ppt
dynamicList.pptdynamicList.ppt
dynamicList.ppt
 
Lab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docxLab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docx
 
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdfInspect the class declaration for a doubly-linked list node in Node-h-.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
 
implement the ListLinked ADT (the declaration is given in ListLinked.pdf
implement the ListLinked ADT (the declaration is given in ListLinked.pdfimplement the ListLinked ADT (the declaration is given in ListLinked.pdf
implement the ListLinked ADT (the declaration is given in ListLinked.pdf
 
Object Oriented Programming Using C++: C++ STL Programming.pptx
Object Oriented Programming Using C++: C++ STL Programming.pptxObject Oriented Programming Using C++: C++ STL Programming.pptx
Object Oriented Programming Using C++: C++ STL Programming.pptx
 
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdfDoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
 
DSA(1).pptx
DSA(1).pptxDSA(1).pptx
DSA(1).pptx
 
Write a program to find the number of comparisons using the binary se.docx
 Write a program to find the number of comparisons using the binary se.docx Write a program to find the number of comparisons using the binary se.docx
Write a program to find the number of comparisons using the binary se.docx
 
Please need help on following program using c++ language. Please inc.pdf
Please need help on following program using c++ language. Please inc.pdfPlease need help on following program using c++ language. Please inc.pdf
Please need help on following program using c++ language. Please inc.pdf
 
Need to be done in C++ Please Sorted number list implementation wit.pdf
Need to be done in C++  Please   Sorted number list implementation wit.pdfNeed to be done in C++  Please   Sorted number list implementation wit.pdf
Need to be done in C++ Please Sorted number list implementation wit.pdf
 
In C++ please, do not alter node.hStep 1 Inspect the Node.h file.pdf
In C++ please, do not alter node.hStep 1 Inspect the Node.h file.pdfIn C++ please, do not alter node.hStep 1 Inspect the Node.h file.pdf
In C++ please, do not alter node.hStep 1 Inspect the Node.h file.pdf
 
10- Consider the following data structure used for implementing a link.docx
10- Consider the following data structure used for implementing a link.docx10- Consider the following data structure used for implementing a link.docx
10- Consider the following data structure used for implementing a link.docx
 
Need to be done in C Please Sorted number list implementation with.pdf
Need to be done in C  Please   Sorted number list implementation with.pdfNeed to be done in C  Please   Sorted number list implementation with.pdf
Need to be done in C Please Sorted number list implementation with.pdf
 
Please help solve this in C++ So the program is working fin.pdf
Please help solve this in C++ So the program is working fin.pdfPlease help solve this in C++ So the program is working fin.pdf
Please help solve this in C++ So the program is working fin.pdf
 
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfHow do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
 
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdfTHE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
 
I need help with this code working Create another project and add yo.pdf
I need help with this code working Create another project and add yo.pdfI need help with this code working Create another project and add yo.pdf
I need help with this code working Create another project and add yo.pdf
 
Lab-2.4 101.pdf
Lab-2.4 101.pdfLab-2.4 101.pdf
Lab-2.4 101.pdf
 
Use the following data set that compares age to average years lef.docx
Use the following data set that compares age to average years lef.docxUse the following data set that compares age to average years lef.docx
Use the following data set that compares age to average years lef.docx
 

More from Jonathan5GxRossk

Write a technical detailed report using Word or PowerPoint or some oth.docx
Write a technical detailed report using Word or PowerPoint or some oth.docxWrite a technical detailed report using Word or PowerPoint or some oth.docx
Write a technical detailed report using Word or PowerPoint or some oth.docxJonathan5GxRossk
 
Write a short note on the following concepts- 1-High touch positioning.docx
Write a short note on the following concepts- 1-High touch positioning.docxWrite a short note on the following concepts- 1-High touch positioning.docx
Write a short note on the following concepts- 1-High touch positioning.docxJonathan5GxRossk
 
Write a Python Code- Assuming that two objects f1 and f2 of type Fract.docx
Write a Python Code- Assuming that two objects f1 and f2 of type Fract.docxWrite a Python Code- Assuming that two objects f1 and f2 of type Fract.docx
Write a Python Code- Assuming that two objects f1 and f2 of type Fract.docxJonathan5GxRossk
 
You are working for a pharmaceutical company that hopes to produce gen.docx
You are working for a pharmaceutical company that hopes to produce gen.docxYou are working for a pharmaceutical company that hopes to produce gen.docx
You are working for a pharmaceutical company that hopes to produce gen.docxJonathan5GxRossk
 
You are the following data for 17 adults who live in Somerville on the.docx
You are the following data for 17 adults who live in Somerville on the.docxYou are the following data for 17 adults who live in Somerville on the.docx
You are the following data for 17 adults who live in Somerville on the.docxJonathan5GxRossk
 
You are required to use the Rail Fence Cipher to encrypt the message-.docx
You are required to use the Rail Fence Cipher to encrypt the message-.docxYou are required to use the Rail Fence Cipher to encrypt the message-.docx
You are required to use the Rail Fence Cipher to encrypt the message-.docxJonathan5GxRossk
 
You are the administrator of a 10-provider group of specialists (3 car.docx
You are the administrator of a 10-provider group of specialists (3 car.docxYou are the administrator of a 10-provider group of specialists (3 car.docx
You are the administrator of a 10-provider group of specialists (3 car.docxJonathan5GxRossk
 
Write brief and clear notes on the following subsets of DCs under the (1).docx
Write brief and clear notes on the following subsets of DCs under the (1).docxWrite brief and clear notes on the following subsets of DCs under the (1).docx
Write brief and clear notes on the following subsets of DCs under the (1).docxJonathan5GxRossk
 
You are looking under a microscope at a cell from an organism that has.docx
You are looking under a microscope at a cell from an organism that has.docxYou are looking under a microscope at a cell from an organism that has.docx
You are looking under a microscope at a cell from an organism that has.docxJonathan5GxRossk
 
Write an interactive C++ program that reads in 2 whole numbers- The pr.docx
Write an interactive C++ program that reads in 2 whole numbers- The pr.docxWrite an interactive C++ program that reads in 2 whole numbers- The pr.docx
Write an interactive C++ program that reads in 2 whole numbers- The pr.docxJonathan5GxRossk
 
Years Financed 4-00- 4-25- 4-50- 4-75- 5-00- 5-25- 5-50- 5-75- 6-00- 6.docx
Years Financed 4-00- 4-25- 4-50- 4-75- 5-00- 5-25- 5-50- 5-75- 6-00- 6.docxYears Financed 4-00- 4-25- 4-50- 4-75- 5-00- 5-25- 5-50- 5-75- 6-00- 6.docx
Years Financed 4-00- 4-25- 4-50- 4-75- 5-00- 5-25- 5-50- 5-75- 6-00- 6.docxJonathan5GxRossk
 
x1-x2 be the onder statistics of a randome sample from a distribartion.docx
x1-x2 be the onder statistics of a randome sample from a distribartion.docxx1-x2 be the onder statistics of a randome sample from a distribartion.docx
x1-x2 be the onder statistics of a randome sample from a distribartion.docxJonathan5GxRossk
 
Write brief notes on these- Fluids and Electrolytes-Acid-Base Balance.docx
Write brief notes on these- Fluids and Electrolytes-Acid-Base Balance.docxWrite brief notes on these- Fluids and Electrolytes-Acid-Base Balance.docx
Write brief notes on these- Fluids and Electrolytes-Acid-Base Balance.docxJonathan5GxRossk
 
X - Y plot - different Y axes- An ecologist is interested in the effec.docx
X - Y plot - different Y axes- An ecologist is interested in the effec.docxX - Y plot - different Y axes- An ecologist is interested in the effec.docx
X - Y plot - different Y axes- An ecologist is interested in the effec.docxJonathan5GxRossk
 
Wruch of the lollowng z scores is bctow the mean- 0-4 001 12 ( ) Click.docx
Wruch of the lollowng z scores is bctow the mean- 0-4 001 12 ( ) Click.docxWruch of the lollowng z scores is bctow the mean- 0-4 001 12 ( ) Click.docx
Wruch of the lollowng z scores is bctow the mean- 0-4 001 12 ( ) Click.docxJonathan5GxRossk
 
Write- compile- and test a program called StudentInfo that displays a.docx
Write- compile- and test a program called StudentInfo that displays a.docxWrite- compile- and test a program called StudentInfo that displays a.docx
Write- compile- and test a program called StudentInfo that displays a.docxJonathan5GxRossk
 
write the MIPS assembly code implementing the following C-C++ statemen.docx
write the MIPS assembly code implementing the following C-C++ statemen.docxwrite the MIPS assembly code implementing the following C-C++ statemen.docx
write the MIPS assembly code implementing the following C-C++ statemen.docxJonathan5GxRossk
 
Write the following mathematical expressions in Python- Assume- x- y-.docx
Write the following mathematical expressions in Python- Assume- x- y-.docxWrite the following mathematical expressions in Python- Assume- x- y-.docx
Write the following mathematical expressions in Python- Assume- x- y-.docxJonathan5GxRossk
 
Write python code which prompts the user to enter one of the following.docx
Write python code which prompts the user to enter one of the following.docxWrite python code which prompts the user to enter one of the following.docx
Write python code which prompts the user to enter one of the following.docxJonathan5GxRossk
 

More from Jonathan5GxRossk (20)

Write a technical detailed report using Word or PowerPoint or some oth.docx
Write a technical detailed report using Word or PowerPoint or some oth.docxWrite a technical detailed report using Word or PowerPoint or some oth.docx
Write a technical detailed report using Word or PowerPoint or some oth.docx
 
Write a short note on the following concepts- 1-High touch positioning.docx
Write a short note on the following concepts- 1-High touch positioning.docxWrite a short note on the following concepts- 1-High touch positioning.docx
Write a short note on the following concepts- 1-High touch positioning.docx
 
Write a Python Code- Assuming that two objects f1 and f2 of type Fract.docx
Write a Python Code- Assuming that two objects f1 and f2 of type Fract.docxWrite a Python Code- Assuming that two objects f1 and f2 of type Fract.docx
Write a Python Code- Assuming that two objects f1 and f2 of type Fract.docx
 
You are working for a pharmaceutical company that hopes to produce gen.docx
You are working for a pharmaceutical company that hopes to produce gen.docxYou are working for a pharmaceutical company that hopes to produce gen.docx
You are working for a pharmaceutical company that hopes to produce gen.docx
 
You are the following data for 17 adults who live in Somerville on the.docx
You are the following data for 17 adults who live in Somerville on the.docxYou are the following data for 17 adults who live in Somerville on the.docx
You are the following data for 17 adults who live in Somerville on the.docx
 
You are required to use the Rail Fence Cipher to encrypt the message-.docx
You are required to use the Rail Fence Cipher to encrypt the message-.docxYou are required to use the Rail Fence Cipher to encrypt the message-.docx
You are required to use the Rail Fence Cipher to encrypt the message-.docx
 
You are the administrator of a 10-provider group of specialists (3 car.docx
You are the administrator of a 10-provider group of specialists (3 car.docxYou are the administrator of a 10-provider group of specialists (3 car.docx
You are the administrator of a 10-provider group of specialists (3 car.docx
 
Write brief and clear notes on the following subsets of DCs under the (1).docx
Write brief and clear notes on the following subsets of DCs under the (1).docxWrite brief and clear notes on the following subsets of DCs under the (1).docx
Write brief and clear notes on the following subsets of DCs under the (1).docx
 
You are looking under a microscope at a cell from an organism that has.docx
You are looking under a microscope at a cell from an organism that has.docxYou are looking under a microscope at a cell from an organism that has.docx
You are looking under a microscope at a cell from an organism that has.docx
 
Write an interactive C++ program that reads in 2 whole numbers- The pr.docx
Write an interactive C++ program that reads in 2 whole numbers- The pr.docxWrite an interactive C++ program that reads in 2 whole numbers- The pr.docx
Write an interactive C++ program that reads in 2 whole numbers- The pr.docx
 
Years Financed 4-00- 4-25- 4-50- 4-75- 5-00- 5-25- 5-50- 5-75- 6-00- 6.docx
Years Financed 4-00- 4-25- 4-50- 4-75- 5-00- 5-25- 5-50- 5-75- 6-00- 6.docxYears Financed 4-00- 4-25- 4-50- 4-75- 5-00- 5-25- 5-50- 5-75- 6-00- 6.docx
Years Financed 4-00- 4-25- 4-50- 4-75- 5-00- 5-25- 5-50- 5-75- 6-00- 6.docx
 
x2-T2+e2.docx
x2-T2+e2.docxx2-T2+e2.docx
x2-T2+e2.docx
 
x1-x2 be the onder statistics of a randome sample from a distribartion.docx
x1-x2 be the onder statistics of a randome sample from a distribartion.docxx1-x2 be the onder statistics of a randome sample from a distribartion.docx
x1-x2 be the onder statistics of a randome sample from a distribartion.docx
 
Write brief notes on these- Fluids and Electrolytes-Acid-Base Balance.docx
Write brief notes on these- Fluids and Electrolytes-Acid-Base Balance.docxWrite brief notes on these- Fluids and Electrolytes-Acid-Base Balance.docx
Write brief notes on these- Fluids and Electrolytes-Acid-Base Balance.docx
 
X - Y plot - different Y axes- An ecologist is interested in the effec.docx
X - Y plot - different Y axes- An ecologist is interested in the effec.docxX - Y plot - different Y axes- An ecologist is interested in the effec.docx
X - Y plot - different Y axes- An ecologist is interested in the effec.docx
 
Wruch of the lollowng z scores is bctow the mean- 0-4 001 12 ( ) Click.docx
Wruch of the lollowng z scores is bctow the mean- 0-4 001 12 ( ) Click.docxWruch of the lollowng z scores is bctow the mean- 0-4 001 12 ( ) Click.docx
Wruch of the lollowng z scores is bctow the mean- 0-4 001 12 ( ) Click.docx
 
Write- compile- and test a program called StudentInfo that displays a.docx
Write- compile- and test a program called StudentInfo that displays a.docxWrite- compile- and test a program called StudentInfo that displays a.docx
Write- compile- and test a program called StudentInfo that displays a.docx
 
write the MIPS assembly code implementing the following C-C++ statemen.docx
write the MIPS assembly code implementing the following C-C++ statemen.docxwrite the MIPS assembly code implementing the following C-C++ statemen.docx
write the MIPS assembly code implementing the following C-C++ statemen.docx
 
Write the following mathematical expressions in Python- Assume- x- y-.docx
Write the following mathematical expressions in Python- Assume- x- y-.docxWrite the following mathematical expressions in Python- Assume- x- y-.docx
Write the following mathematical expressions in Python- Assume- x- y-.docx
 
Write python code which prompts the user to enter one of the following.docx
Write python code which prompts the user to enter one of the following.docxWrite python code which prompts the user to enter one of the following.docx
Write python code which prompts the user to enter one of the following.docx
 

Recently uploaded

An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismDabee Kamal
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint23600690
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesAmanpreetKaur157993
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................MirzaAbrarBaig5
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjMohammed Sikander
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文中 央社
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSean M. Fox
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...Nguyen Thanh Tu Collection
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppCeline George
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...Nguyen Thanh Tu Collection
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesPooky Knightsmith
 
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
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...Nguyen Thanh Tu Collection
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024Borja Sotomayor
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project researchCaitlinCummins3
 

Recently uploaded (20)

An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
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...
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 

You are required to implement the following functions for doubly linke.docx

  • 1. You are required to implement the following functions for doubly linked lists. Note that code for creating a doubly linked list from an array of values is given to you, as well as testing code (driver program) to make sure that all functions work as expected. 1. find: Returns true if the given value is found in the list, and false otherwise. template <typename Object> bool findInDLL(DoubleNode<Object>* head, Object value); 2. insertBefore: Finds a given value and inserts a new node before it with a new value. Returns true if the insertion is successful, else false. template <typename Object> bool insertBeforeDLL(DoubleNode<Object>*& head, Object value, Object newValue); 3. erase: Finds a given value and deletes the matching node from the linked list. Returns true if the insertion is successful, else false. template <typename Object> bool eraseInDLL(DoubleNode<Object>*& head, Object value); Sample output: Printing Double linked list: 1 2 4 7 6 8 Finding 7 in the List: 7 exist in the list Inserting 3 before 4 : 1 2 3 4 7 6 8 Inserting 0 before 1 (inserting at the start of the list): 0 1 2 3 4 7 6 8 Deleting 3: 0 1 2 4 7 6 8 Deleting 8 (deleting last element in the list): 0 1 2 4 7 6 Deleting 0 (deleting first element in the list): 1 2 4 7 6 Deleting -99 (trying to delete an element which is not present in the list): Value not Found! GIVEN THE C++ TEMPLATE PROGRAM
  • 2. #include <iostream> #include <string> using namespace std; //Doubly Linked List structure template <typename Object> struct DoubleNode { Object data; DoubleNode *prev; DoubleNode *next; DoubleNode(const Object & d = Object{}, DoubleNode * p = nullptr, DoubleNode * n = nullptr) : data{ d }, prev{ p }, next{ n } { } }; //function to create Doubly Linked List with values template <typename Object> DoubleNode<Object>* createDLL(Object ary[], int size) { DoubleNode<Object>* first = new DoubleNode<Object>(ary[0]); DoubleNode<Object>* temp = first; for (int i = 1; i < size; i++) { DoubleNode<Object>* node = new DoubleNode<Object>(ary[i]); temp->next = node; node->prev = temp; temp = node; } return first; } template <typename Object> void printDLL(DoubleNode<Object>* head) { while (head != nullptr) { cout << head->data << "t"; head = head->next; } cout << endl; } template <typename Object> bool findInDLL(DoubleNode<Object>* head, Object value) { //your code goes here } template <typename Object>
  • 3. bool insertBeforeDLL(DoubleNode<Object>* & head, Object givenValue, Object newValue) { DoubleNode<Object> *newNode = new DoubleNode<Object>(newValue); //your code goes here } template <typename Object> bool eraseInDLL(DoubleNode<Object>*& head, Object givenValue) { DoubleNode<Object> *temp = head; //your code goes here } int main() { int ary[] = { 1,2,4,7,6,8 }, size = 6; DoubleNode<int>* head = createDLL<int>(ary, size); cout << "Printing Double linked list: n"; printDLL(head); cout << "nFinding 7 in the List: n"; if (findInDLL(head, 7)) cout << "7 exist in the listn"; //Testing insertBefore function cout << "nInserting 3 before 4 :n"; bool success = insertBeforeDLL(head, 4, 3); if (success) printDLL(head); else cout << "Value not Found! n"; cout << "nInserting 0 before 1 (inserting at the start of the list):n"; success = insertBeforeDLL(head, 1, 0); if (success) printDLL(head); else cout << "Value not Found! n"; cout << "nDeleting 3:n "; success = eraseInDLL(head, 3); if (success) printDLL(head); else cout << "Value not Found! n"; cout << "nDeleting 8 (deleting last element in the list):n "; success = eraseInDLL(head, 8); if (success) printDLL(head);
  • 4. else cout << "Value not Found! n"; cout << "nDeleting 0 (deleting first element in the list):n "; success = eraseInDLL(head, 0); if (success) printDLL(head); else cout << "Value not Found! n"; cout << "nDeleting -99 (trying to delete an element which is not present in the list):n "; success = eraseInDLL(head, -99); if (success) printDLL(head); else cout << "Value not Found! n"; return 0; }