SlideShare a Scribd company logo
I need to fill-in //TODO's in .cpp file and in .h file
Could someone help me at least with few of them to give me an idea how deal with it.
***SinglyLinkedList.cpp
#include
#include
#include "SinglyLinkedList.h"
void test_constructor() {
SinglyLinkedList lst = {100, 200, 300, 400, 500};
assert(*lst.at(0) == 100);
assert(*lst.at(1) == 200);
assert(*lst.at(2) == 300);
assert(*lst.at(3) == 400);
assert(*lst.at(4) == 500);
assert(lst.size() == 5);
}
void test_remove() {
SinglyLinkedList lst = {100, 200, 300, 400, 500};
lst.remove(2);
assert(*lst.at(0) == 100);
assert(*lst.at(1) == 200);
assert(*lst.at(2) == 400);
assert(*lst.at(3) == 500);
assert(lst.size() == 4);
}
void test_insert() {
// TODO
}
void test_push_back() {
// TODO
}
void test_push_front() {
// TODO
}
void test_append() {
// TODO
}
void test_sum() {
// TODO
}
int main() {
test_constructor();
test_remove();
test_insert();
test_push_back();
test_push_front();
test_append();
test_sum();
}
***SinglyLinkedList.h
#include
#include
template
class SinglyLinkedList {
// Nested class representing the nodes in the list.
class SinglyLinkedListNode {
public:
// The value stored in this node.
T value;
// The next node in the sequence.
SinglyLinkedListNode *next;
SinglyLinkedListNode(T value) :
value(value), next(nullptr) {}
SinglyLinkedListNode(T value, SinglyLinkedListNode *next) :
value(value), next(next) {}
// Return the size (length) of the linked list.
std::size_t size();
};
SinglyLinkedListNode *head;
SinglyLinkedListNode *tail;
public:
// Constructs a new SinglyLinkedList from an initializer_list of type T[].
// This is mostly for convenience, especially when testing.
SinglyLinkedList(std::initializer_list items) : head(nullptr), tail(nullptr) {
if (items.size() == 0) {
return;
}
// initializer_lists were designed to be used iteratively,
// so thats what we do.
// Can you think of how to write this recursively?
auto it = items.begin();
while (it != items.end()) {
this->push_back(*it++);
}
}
// Return a pointer to the value at the given index.
// If the index is larger than the size of the list,
// return a nullptr.
//
// ASIDE: We will cover exceptions later.
T* at(std::size_t i);
// Pushes a new node onto the back of the list.
void push_back(T value);
// Pushes a new node onto the front of the list.
void push_front(T value);
// Return the size (length) of the linked list.
std::size_t size();
// Remove the specified node from the list.
void remove(std::size_t i);
// Insert the value at the index.
void insert(std::size_t i, T value);
// Append the given list to this one.
void append(SinglyLinkedList list);
};
template
T* SinglyLinkedList::at(std::size_t i) {
// TODO
}
template
void SinglyLinkedList::push_back(T value) {
// TODO
// Make sure that this is a O(1) operation!
}
template
void SinglyLinkedList::push_front(T value) {
// TODO
// Make sure that this is a O(1) operation!
}
template
void SinglyLinkedList::remove(std::size_t i) {
// TODO
// Don't forget to not only unlink the node, but to delete the memory.
}
template
void SinglyLinkedList::insert(std::size_t i, T value) {
// TODO
// Don't forget to not only unlink the node, but to delete the memory.
}
template
void SinglyLinkedList::append(SinglyLinkedList list) {
// TODO
}
template
std::size_t SinglyLinkedList::size() {
if (this->head == nullptr) {
return 0;
} else {
return this->head->size();
}
}
template
std::size_t SinglyLinkedList::SinglyLinkedListNode::size() {
if (this == nullptr) {
return 0;
} else if (this->next == nullptr) {
return 1;
} else {
return 1 + this->next->size();
}
}
// Takes a reference to a list of integers as an argument,
// and returns the sum of the items in the list.
long sum(const SinglyLinkedList& list) {
// TODO
}
Solution
#include
#include
#include
struct node
{
int info;
struct node *next;
}*start;
class SingleLinkedList
{
public:
node* create_node(int);
void insert_begin();
void insert_pos();
void insert_last();
void delete_pos();
void sort();
void search();
void update();
void reverse();
void display();
SingleLinkedList()
{
start = NULL;
}
};
void main()
{
int choice, nodes, element, position, i;
SingleLinkedList sl;
start = NULL;
while (1)
{
cout<>choice;
switch(choice)
{
case 1:
cout<<"Inserting Node at Beginning: "<info = value;
temp->next = NULL;
return temp;
}
}
void SingleLinkedList::insert_begin()
{
int value;
cout<<"Enter the value to be inserted: ";
cin>>value;
struct node *temp, *p;
temp = create_node(value);
if (start == NULL)
{
start = temp;
start->next = NULL;
}
else
{
p = start;
start = temp;
start->next = p;
}
cout<<"Element Inserted at beginning"<>value;
struct node *temp, *s;
temp = create_node(value);
s = start;
while (s->next != NULL)
{
s = s->next;
}
temp->next = NULL;
s->next = temp;
cout<<"Element Inserted at last"<>value;
struct node *temp, *s, *ptr;
temp = create_node(value);
cout<<"Enter the postion at which node to be inserted: ";
cin>>pos;
int i;
s = start;
while (s != NULL)
{
s = s->next;
counter++;
}
if (pos == 1)
{
if (start == NULL)
{
start = temp;
start->next = NULL;
}
else
{
ptr = start;
start = temp;
start->next = ptr;
}
}
else if (pos > 1 && pos <= counter)
{
s = start;
for (i = 1; i < pos; i++)
{
ptr = s;
s = s->next;
}
ptr->next = temp;
temp->next = s;
}
else
{
cout<<"Positon out of range"<next;s !=NULL;s = s->next)
{
if (ptr->info > s->info)
{
value = ptr->info;
ptr->info = s->info;
s->info = value;
}
}
ptr = ptr->next;
}
}
void SingleLinkedList::delete_pos()
{
int pos, i, counter = 0;
if (start == NULL)
{
cout<<"List is empty"<>pos;
struct node *s, *ptr;
s = start;
if (pos == 1)
{
start = s->next;
}
else
{
while (s != NULL)
{
s = s->next;
counter++;
}
if (pos > 0 && pos <= counter)
{
s = start;
for (i = 1;i < pos;i++)
{
ptr = s;
s = s->next;
}
ptr->next = s->next;
}
else
{
cout<<"Position out of range"<>pos;
cout<<"Enter the new value: ";
cin>>value;
struct node *s, *ptr;
s = start;
if (pos == 1)
{
start->info = value;
}
else
{
for (i = 0;i < pos - 1;i++)
{
if (s == NULL)
{
cout<<"There are less than "<next;
}
s->info = value;
}
cout<<"Node Updated"<>value;
struct node *s;
s = start;
while (s != NULL)
{
pos++;
if (s->info == value)
{
flag = true;
cout<<"Element "<next;
}
if (!flag)
cout<<"Element "<next == NULL)
{
return;
}
ptr1 = start;
ptr2 = ptr1->next;
ptr3 = ptr2->next;
ptr1->next = NULL;
ptr2->next = ptr1;
while (ptr3 != NULL)
{
ptr1 = ptr2;
ptr2 = ptr3;
ptr3 = ptr3->next;
ptr2->next = ptr1;
}
start = ptr2;
}
void SingleLinkedList::display()
{
struct node *temp;
if (start == NULL)
{
cout<<"The List is Empty"<info<<"->";
temp = temp->next;
}
cout<<"NULL"<

More Related Content

Similar to I need to fill-in TODOs in .cpp file and in .h file Could some.pdf

Please solve the TODO parts include LinkedListcpph tem.pdf
Please solve the TODO parts  include LinkedListcpph tem.pdfPlease solve the TODO parts  include LinkedListcpph tem.pdf
Please solve the TODO parts include LinkedListcpph tem.pdf
aggarwalopticalsco
 
hi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdfhi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdf
archgeetsenterprises
 
C++11 - STL Additions
C++11 - STL AdditionsC++11 - STL Additions
C++11 - STL Additions
GlobalLogic Ukraine
 
Shapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptShapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop concept
kinan keshkeh
 
C++ projectMachine Problem 7 - HashingWrite a program to do the .pdf
C++ projectMachine Problem 7 - HashingWrite a program to do the .pdfC++ projectMachine Problem 7 - HashingWrite a program to do the .pdf
C++ projectMachine Problem 7 - HashingWrite a program to do the .pdf
feelinggift
 
Lab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docxLab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docx
teyaj1
 
(C++ exercise) 1.Implement a circular, doubly linked list with a has.docx
(C++ exercise) 1.Implement a circular, doubly linked list with a has.docx(C++ exercise) 1.Implement a circular, doubly linked list with a has.docx
(C++ exercise) 1.Implement a circular, doubly linked list with a has.docx
ajoy21
 
#includeiostream #includecstdio #includecstdlib using na.pdf
#includeiostream #includecstdio #includecstdlib using na.pdf#includeiostream #includecstdio #includecstdlib using na.pdf
#includeiostream #includecstdio #includecstdlib using na.pdf
harihelectronicspune
 
#include iostream#include d_node.h #include d_nodel.h.docx
#include iostream#include d_node.h #include d_nodel.h.docx#include iostream#include d_node.h #include d_nodel.h.docx
#include iostream#include d_node.h #include d_nodel.h.docx
ajoy21
 
03 stacks and_queues_using_arrays
03 stacks and_queues_using_arrays03 stacks and_queues_using_arrays
03 stacks and_queues_using_arraystameemyousaf
 
C++11
C++11C++11
Implement the unsorted single linked list as we did in the class and .pdf
Implement the unsorted single linked list as we did in the class and .pdfImplement the unsorted single linked list as we did in the class and .pdf
Implement the unsorted single linked list as we did in the class and .pdf
arihantstoneart
 
dynamicList.ppt
dynamicList.pptdynamicList.ppt
dynamicList.ppt
ssuser0be977
 
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
 
Arrays
ArraysArrays
Shapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptShapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop concept
kinan keshkeh
 
C++ Program to Implement Singly Linked List #includeiostream.pdf
 C++ Program to Implement Singly Linked List #includeiostream.pdf C++ Program to Implement Singly Linked List #includeiostream.pdf
C++ Program to Implement Singly Linked List #includeiostream.pdf
angelsfashion1
 
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdfC++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
poblettesedanoree498
 

Similar to I need to fill-in TODOs in .cpp file and in .h file Could some.pdf (20)

Please solve the TODO parts include LinkedListcpph tem.pdf
Please solve the TODO parts  include LinkedListcpph tem.pdfPlease solve the TODO parts  include LinkedListcpph tem.pdf
Please solve the TODO parts include LinkedListcpph tem.pdf
 
Ds 2 cycle
Ds 2 cycleDs 2 cycle
Ds 2 cycle
 
hi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdfhi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdf
 
C++11 - STL Additions
C++11 - STL AdditionsC++11 - STL Additions
C++11 - STL Additions
 
Shapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptShapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop concept
 
C++ projectMachine Problem 7 - HashingWrite a program to do the .pdf
C++ projectMachine Problem 7 - HashingWrite a program to do the .pdfC++ projectMachine Problem 7 - HashingWrite a program to do the .pdf
C++ projectMachine Problem 7 - HashingWrite a program to do the .pdf
 
Lab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docxLab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docx
 
(C++ exercise) 1.Implement a circular, doubly linked list with a has.docx
(C++ exercise) 1.Implement a circular, doubly linked list with a has.docx(C++ exercise) 1.Implement a circular, doubly linked list with a has.docx
(C++ exercise) 1.Implement a circular, doubly linked list with a has.docx
 
#includeiostream #includecstdio #includecstdlib using na.pdf
#includeiostream #includecstdio #includecstdlib using na.pdf#includeiostream #includecstdio #includecstdlib using na.pdf
#includeiostream #includecstdio #includecstdlib using na.pdf
 
#include iostream#include d_node.h #include d_nodel.h.docx
#include iostream#include d_node.h #include d_nodel.h.docx#include iostream#include d_node.h #include d_nodel.h.docx
#include iostream#include d_node.h #include d_nodel.h.docx
 
03 stacks and_queues_using_arrays
03 stacks and_queues_using_arrays03 stacks and_queues_using_arrays
03 stacks and_queues_using_arrays
 
C++11
C++11C++11
C++11
 
Implement the unsorted single linked list as we did in the class and .pdf
Implement the unsorted single linked list as we did in the class and .pdfImplement the unsorted single linked list as we did in the class and .pdf
Implement the unsorted single linked list as we did in the class and .pdf
 
C program
C programC program
C program
 
dynamicList.ppt
dynamicList.pptdynamicList.ppt
dynamicList.ppt
 
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
 
Arrays
ArraysArrays
Arrays
 
Shapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptShapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop concept
 
C++ Program to Implement Singly Linked List #includeiostream.pdf
 C++ Program to Implement Singly Linked List #includeiostream.pdf C++ Program to Implement Singly Linked List #includeiostream.pdf
C++ Program to Implement Singly Linked List #includeiostream.pdf
 
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdfC++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
 

More from forladies

You isolated an enveloped RNA virus. Purified RNA is not capable of .pdf
You isolated an enveloped RNA virus. Purified RNA is not capable of .pdfYou isolated an enveloped RNA virus. Purified RNA is not capable of .pdf
You isolated an enveloped RNA virus. Purified RNA is not capable of .pdf
forladies
 
What properties should the following molecules NOT have in common (S.pdf
What properties should the following molecules NOT have in common (S.pdfWhat properties should the following molecules NOT have in common (S.pdf
What properties should the following molecules NOT have in common (S.pdf
forladies
 
What is the difference between Schedule C and Schedule E income (i.e.pdf
What is the difference between Schedule C and Schedule E income (i.e.pdfWhat is the difference between Schedule C and Schedule E income (i.e.pdf
What is the difference between Schedule C and Schedule E income (i.e.pdf
forladies
 
What are the ethical and legal concerns associated with managing tel.pdf
What are the ethical and legal concerns associated with managing tel.pdfWhat are the ethical and legal concerns associated with managing tel.pdf
What are the ethical and legal concerns associated with managing tel.pdf
forladies
 
Using the Graphical User Interface (GUI)Create a user nam.pdf
Using the Graphical User Interface (GUI)Create a user nam.pdfUsing the Graphical User Interface (GUI)Create a user nam.pdf
Using the Graphical User Interface (GUI)Create a user nam.pdf
forladies
 
The adjusting entry to record the salaries earned due to employees f.pdf
The adjusting entry to record the salaries earned due to employees f.pdfThe adjusting entry to record the salaries earned due to employees f.pdf
The adjusting entry to record the salaries earned due to employees f.pdf
forladies
 
TF A document type definition (DTD) can be referenced by many Exten.pdf
TF A document type definition (DTD) can be referenced by many Exten.pdfTF A document type definition (DTD) can be referenced by many Exten.pdf
TF A document type definition (DTD) can be referenced by many Exten.pdf
forladies
 
Summarize the first and the second checkpoints during T cell develop.pdf
Summarize the first and the second checkpoints during T cell develop.pdfSummarize the first and the second checkpoints during T cell develop.pdf
Summarize the first and the second checkpoints during T cell develop.pdf
forladies
 
PLEASE HELP!!Loren Seguara and Dale Johnson both work for Southern.pdf
PLEASE HELP!!Loren Seguara and Dale Johnson both work for Southern.pdfPLEASE HELP!!Loren Seguara and Dale Johnson both work for Southern.pdf
PLEASE HELP!!Loren Seguara and Dale Johnson both work for Southern.pdf
forladies
 
Please answer the following at the bottom of the case. ThanksTo ne.pdf
Please answer the following at the bottom of the case. ThanksTo ne.pdfPlease answer the following at the bottom of the case. ThanksTo ne.pdf
Please answer the following at the bottom of the case. ThanksTo ne.pdf
forladies
 
Mitchell sets sail for the Chemiosmotic New World, despite dire w.pdf
Mitchell sets sail for the Chemiosmotic New World, despite dire w.pdfMitchell sets sail for the Chemiosmotic New World, despite dire w.pdf
Mitchell sets sail for the Chemiosmotic New World, despite dire w.pdf
forladies
 
Learn the genetics vocabulary (see HW4)] For each of the following ge.pdf
Learn the genetics vocabulary (see HW4)] For each of the following ge.pdfLearn the genetics vocabulary (see HW4)] For each of the following ge.pdf
Learn the genetics vocabulary (see HW4)] For each of the following ge.pdf
forladies
 
If nominal GDP is 28000 and the money supply is 7000, what is velocit.pdf
If nominal GDP is 28000 and the money supply is 7000, what is velocit.pdfIf nominal GDP is 28000 and the money supply is 7000, what is velocit.pdf
If nominal GDP is 28000 and the money supply is 7000, what is velocit.pdf
forladies
 
Investments in trade securities are always short term investments. T.pdf
Investments in trade securities are always short term investments. T.pdfInvestments in trade securities are always short term investments. T.pdf
Investments in trade securities are always short term investments. T.pdf
forladies
 
Information Securityfind an article online discussing defense-in-d.pdf
Information Securityfind an article online discussing defense-in-d.pdfInformation Securityfind an article online discussing defense-in-d.pdf
Information Securityfind an article online discussing defense-in-d.pdf
forladies
 
implement the following funtions. myg1 and myg2 are seperate. x and .pdf
implement the following funtions. myg1 and myg2 are seperate. x and .pdfimplement the following funtions. myg1 and myg2 are seperate. x and .pdf
implement the following funtions. myg1 and myg2 are seperate. x and .pdf
forladies
 
If two peers share a link in the overlay (they are neighbors in the .pdf
If two peers share a link in the overlay (they are neighbors in the .pdfIf two peers share a link in the overlay (they are neighbors in the .pdf
If two peers share a link in the overlay (they are neighbors in the .pdf
forladies
 
how important is Negative Emotionality to an accounting career plea.pdf
how important is Negative Emotionality to an accounting career plea.pdfhow important is Negative Emotionality to an accounting career plea.pdf
how important is Negative Emotionality to an accounting career plea.pdf
forladies
 
How do I know whether miscellaneous expense goes on top or bottom of.pdf
How do I know whether miscellaneous expense goes on top or bottom of.pdfHow do I know whether miscellaneous expense goes on top or bottom of.pdf
How do I know whether miscellaneous expense goes on top or bottom of.pdf
forladies
 
Given a 1024 by 1024 RAM block, answer the following questions a) If.pdf
Given a 1024 by 1024 RAM block, answer the following questions  a) If.pdfGiven a 1024 by 1024 RAM block, answer the following questions  a) If.pdf
Given a 1024 by 1024 RAM block, answer the following questions a) If.pdf
forladies
 

More from forladies (20)

You isolated an enveloped RNA virus. Purified RNA is not capable of .pdf
You isolated an enveloped RNA virus. Purified RNA is not capable of .pdfYou isolated an enveloped RNA virus. Purified RNA is not capable of .pdf
You isolated an enveloped RNA virus. Purified RNA is not capable of .pdf
 
What properties should the following molecules NOT have in common (S.pdf
What properties should the following molecules NOT have in common (S.pdfWhat properties should the following molecules NOT have in common (S.pdf
What properties should the following molecules NOT have in common (S.pdf
 
What is the difference between Schedule C and Schedule E income (i.e.pdf
What is the difference between Schedule C and Schedule E income (i.e.pdfWhat is the difference between Schedule C and Schedule E income (i.e.pdf
What is the difference between Schedule C and Schedule E income (i.e.pdf
 
What are the ethical and legal concerns associated with managing tel.pdf
What are the ethical and legal concerns associated with managing tel.pdfWhat are the ethical and legal concerns associated with managing tel.pdf
What are the ethical and legal concerns associated with managing tel.pdf
 
Using the Graphical User Interface (GUI)Create a user nam.pdf
Using the Graphical User Interface (GUI)Create a user nam.pdfUsing the Graphical User Interface (GUI)Create a user nam.pdf
Using the Graphical User Interface (GUI)Create a user nam.pdf
 
The adjusting entry to record the salaries earned due to employees f.pdf
The adjusting entry to record the salaries earned due to employees f.pdfThe adjusting entry to record the salaries earned due to employees f.pdf
The adjusting entry to record the salaries earned due to employees f.pdf
 
TF A document type definition (DTD) can be referenced by many Exten.pdf
TF A document type definition (DTD) can be referenced by many Exten.pdfTF A document type definition (DTD) can be referenced by many Exten.pdf
TF A document type definition (DTD) can be referenced by many Exten.pdf
 
Summarize the first and the second checkpoints during T cell develop.pdf
Summarize the first and the second checkpoints during T cell develop.pdfSummarize the first and the second checkpoints during T cell develop.pdf
Summarize the first and the second checkpoints during T cell develop.pdf
 
PLEASE HELP!!Loren Seguara and Dale Johnson both work for Southern.pdf
PLEASE HELP!!Loren Seguara and Dale Johnson both work for Southern.pdfPLEASE HELP!!Loren Seguara and Dale Johnson both work for Southern.pdf
PLEASE HELP!!Loren Seguara and Dale Johnson both work for Southern.pdf
 
Please answer the following at the bottom of the case. ThanksTo ne.pdf
Please answer the following at the bottom of the case. ThanksTo ne.pdfPlease answer the following at the bottom of the case. ThanksTo ne.pdf
Please answer the following at the bottom of the case. ThanksTo ne.pdf
 
Mitchell sets sail for the Chemiosmotic New World, despite dire w.pdf
Mitchell sets sail for the Chemiosmotic New World, despite dire w.pdfMitchell sets sail for the Chemiosmotic New World, despite dire w.pdf
Mitchell sets sail for the Chemiosmotic New World, despite dire w.pdf
 
Learn the genetics vocabulary (see HW4)] For each of the following ge.pdf
Learn the genetics vocabulary (see HW4)] For each of the following ge.pdfLearn the genetics vocabulary (see HW4)] For each of the following ge.pdf
Learn the genetics vocabulary (see HW4)] For each of the following ge.pdf
 
If nominal GDP is 28000 and the money supply is 7000, what is velocit.pdf
If nominal GDP is 28000 and the money supply is 7000, what is velocit.pdfIf nominal GDP is 28000 and the money supply is 7000, what is velocit.pdf
If nominal GDP is 28000 and the money supply is 7000, what is velocit.pdf
 
Investments in trade securities are always short term investments. T.pdf
Investments in trade securities are always short term investments. T.pdfInvestments in trade securities are always short term investments. T.pdf
Investments in trade securities are always short term investments. T.pdf
 
Information Securityfind an article online discussing defense-in-d.pdf
Information Securityfind an article online discussing defense-in-d.pdfInformation Securityfind an article online discussing defense-in-d.pdf
Information Securityfind an article online discussing defense-in-d.pdf
 
implement the following funtions. myg1 and myg2 are seperate. x and .pdf
implement the following funtions. myg1 and myg2 are seperate. x and .pdfimplement the following funtions. myg1 and myg2 are seperate. x and .pdf
implement the following funtions. myg1 and myg2 are seperate. x and .pdf
 
If two peers share a link in the overlay (they are neighbors in the .pdf
If two peers share a link in the overlay (they are neighbors in the .pdfIf two peers share a link in the overlay (they are neighbors in the .pdf
If two peers share a link in the overlay (they are neighbors in the .pdf
 
how important is Negative Emotionality to an accounting career plea.pdf
how important is Negative Emotionality to an accounting career plea.pdfhow important is Negative Emotionality to an accounting career plea.pdf
how important is Negative Emotionality to an accounting career plea.pdf
 
How do I know whether miscellaneous expense goes on top or bottom of.pdf
How do I know whether miscellaneous expense goes on top or bottom of.pdfHow do I know whether miscellaneous expense goes on top or bottom of.pdf
How do I know whether miscellaneous expense goes on top or bottom of.pdf
 
Given a 1024 by 1024 RAM block, answer the following questions a) If.pdf
Given a 1024 by 1024 RAM block, answer the following questions  a) If.pdfGiven a 1024 by 1024 RAM block, answer the following questions  a) If.pdf
Given a 1024 by 1024 RAM block, answer the following questions a) If.pdf
 

Recently uploaded

Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 

Recently uploaded (20)

Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 

I need to fill-in TODOs in .cpp file and in .h file Could some.pdf

  • 1. I need to fill-in //TODO's in .cpp file and in .h file Could someone help me at least with few of them to give me an idea how deal with it. ***SinglyLinkedList.cpp #include #include #include "SinglyLinkedList.h" void test_constructor() { SinglyLinkedList lst = {100, 200, 300, 400, 500}; assert(*lst.at(0) == 100); assert(*lst.at(1) == 200); assert(*lst.at(2) == 300); assert(*lst.at(3) == 400); assert(*lst.at(4) == 500); assert(lst.size() == 5); } void test_remove() { SinglyLinkedList lst = {100, 200, 300, 400, 500}; lst.remove(2); assert(*lst.at(0) == 100); assert(*lst.at(1) == 200); assert(*lst.at(2) == 400); assert(*lst.at(3) == 500); assert(lst.size() == 4); } void test_insert() { // TODO } void test_push_back() { // TODO } void test_push_front() { // TODO } void test_append() { // TODO
  • 2. } void test_sum() { // TODO } int main() { test_constructor(); test_remove(); test_insert(); test_push_back(); test_push_front(); test_append(); test_sum(); } ***SinglyLinkedList.h #include #include template class SinglyLinkedList { // Nested class representing the nodes in the list. class SinglyLinkedListNode { public: // The value stored in this node. T value; // The next node in the sequence. SinglyLinkedListNode *next; SinglyLinkedListNode(T value) : value(value), next(nullptr) {} SinglyLinkedListNode(T value, SinglyLinkedListNode *next) : value(value), next(next) {} // Return the size (length) of the linked list. std::size_t size(); }; SinglyLinkedListNode *head; SinglyLinkedListNode *tail; public: // Constructs a new SinglyLinkedList from an initializer_list of type T[].
  • 3. // This is mostly for convenience, especially when testing. SinglyLinkedList(std::initializer_list items) : head(nullptr), tail(nullptr) { if (items.size() == 0) { return; } // initializer_lists were designed to be used iteratively, // so thats what we do. // Can you think of how to write this recursively? auto it = items.begin(); while (it != items.end()) { this->push_back(*it++); } } // Return a pointer to the value at the given index. // If the index is larger than the size of the list, // return a nullptr. // // ASIDE: We will cover exceptions later. T* at(std::size_t i); // Pushes a new node onto the back of the list. void push_back(T value); // Pushes a new node onto the front of the list. void push_front(T value); // Return the size (length) of the linked list. std::size_t size(); // Remove the specified node from the list. void remove(std::size_t i); // Insert the value at the index. void insert(std::size_t i, T value); // Append the given list to this one. void append(SinglyLinkedList list); }; template T* SinglyLinkedList::at(std::size_t i) { // TODO }
  • 4. template void SinglyLinkedList::push_back(T value) { // TODO // Make sure that this is a O(1) operation! } template void SinglyLinkedList::push_front(T value) { // TODO // Make sure that this is a O(1) operation! } template void SinglyLinkedList::remove(std::size_t i) { // TODO // Don't forget to not only unlink the node, but to delete the memory. } template void SinglyLinkedList::insert(std::size_t i, T value) { // TODO // Don't forget to not only unlink the node, but to delete the memory. } template void SinglyLinkedList::append(SinglyLinkedList list) { // TODO } template std::size_t SinglyLinkedList::size() { if (this->head == nullptr) { return 0; } else { return this->head->size(); } } template std::size_t SinglyLinkedList::SinglyLinkedListNode::size() { if (this == nullptr) { return 0;
  • 5. } else if (this->next == nullptr) { return 1; } else { return 1 + this->next->size(); } } // Takes a reference to a list of integers as an argument, // and returns the sum of the items in the list. long sum(const SinglyLinkedList& list) { // TODO } Solution #include #include #include struct node { int info; struct node *next; }*start; class SingleLinkedList { public: node* create_node(int); void insert_begin(); void insert_pos(); void insert_last(); void delete_pos(); void sort(); void search(); void update(); void reverse(); void display(); SingleLinkedList()
  • 6. { start = NULL; } }; void main() { int choice, nodes, element, position, i; SingleLinkedList sl; start = NULL; while (1) { cout<>choice; switch(choice) { case 1: cout<<"Inserting Node at Beginning: "<info = value; temp->next = NULL; return temp; } } void SingleLinkedList::insert_begin() { int value; cout<<"Enter the value to be inserted: "; cin>>value; struct node *temp, *p; temp = create_node(value); if (start == NULL) { start = temp; start->next = NULL; } else { p = start; start = temp;
  • 7. start->next = p; } cout<<"Element Inserted at beginning"<>value; struct node *temp, *s; temp = create_node(value); s = start; while (s->next != NULL) { s = s->next; } temp->next = NULL; s->next = temp; cout<<"Element Inserted at last"<>value; struct node *temp, *s, *ptr; temp = create_node(value); cout<<"Enter the postion at which node to be inserted: "; cin>>pos; int i; s = start; while (s != NULL) { s = s->next; counter++; } if (pos == 1) { if (start == NULL) { start = temp; start->next = NULL; } else { ptr = start; start = temp; start->next = ptr;
  • 8. } } else if (pos > 1 && pos <= counter) { s = start; for (i = 1; i < pos; i++) { ptr = s; s = s->next; } ptr->next = temp; temp->next = s; } else { cout<<"Positon out of range"<next;s !=NULL;s = s->next) { if (ptr->info > s->info) { value = ptr->info; ptr->info = s->info; s->info = value; } } ptr = ptr->next; } } void SingleLinkedList::delete_pos() { int pos, i, counter = 0; if (start == NULL) { cout<<"List is empty"<>pos; struct node *s, *ptr; s = start; if (pos == 1)
  • 9. { start = s->next; } else { while (s != NULL) { s = s->next; counter++; } if (pos > 0 && pos <= counter) { s = start; for (i = 1;i < pos;i++) { ptr = s; s = s->next; } ptr->next = s->next; } else { cout<<"Position out of range"<>pos; cout<<"Enter the new value: "; cin>>value; struct node *s, *ptr; s = start; if (pos == 1) { start->info = value; } else { for (i = 0;i < pos - 1;i++) { if (s == NULL)
  • 10. { cout<<"There are less than "<next; } s->info = value; } cout<<"Node Updated"<>value; struct node *s; s = start; while (s != NULL) { pos++; if (s->info == value) { flag = true; cout<<"Element "<next; } if (!flag) cout<<"Element "<next == NULL) { return; } ptr1 = start; ptr2 = ptr1->next; ptr3 = ptr2->next; ptr1->next = NULL; ptr2->next = ptr1; while (ptr3 != NULL) { ptr1 = ptr2; ptr2 = ptr3; ptr3 = ptr3->next; ptr2->next = ptr1; } start = ptr2; } void SingleLinkedList::display()
  • 11. { struct node *temp; if (start == NULL) { cout<<"The List is Empty"<info<<"->"; temp = temp->next; } cout<<"NULL"<