SlideShare a Scribd company logo
1 of 6
Download to read offline
Need to be done in C++ Please
Sorted number list implementation with linked lists
Step 1: Inspect the Node.h file
Inspect the class declaration for a doubly-linked list node in Node.h. Access Node.h by clicking
on the orange arrow next to main.cpp at the top of the coding window. The Node class has three
member variables:
a double data value,
a pointer to the next node, and
a pointer to the previous node.
Each member variable is protected. So code outside of the class must use the provided getter and
setter member functions to get or set a member variable.
Node.h is read only, since no changes are required.
Step 2: Implement the Insert() member function
A class for a sorted, doubly-linked list is declared in SortedNumberList.h. Implement the
SortedNumberList class's Insert() member function. The function must create a new node with
the parameter value, then insert the node into the proper sorted position in the linked list. Ex:
Suppose a SortedNumberList's current list is 23 47.25 86, then Insert(33.5) is called. A new node
with data value 33.5 is created and inserted between 23 and 47.25, thus preserving the list's
sorted order and yielding: 23 35.5 47.25 86
Step 3: Test in develop mode
Code in main() takes a space-separated list of numbers and inserts each into a SortedNumberList.
The list is displayed after each insertion. Ex: If input is
then output is:
Try various program inputs, ensuring that each outputs a sorted list.
Step 4: Implement the Remove() member function
Implement the SortedNumberList class's Remove() member function. The function takes a
parameter for the number to be removed from the list. If the number does not exist in the list, the
list is not changed and false is returned. Otherwise, the first instance of the number is removed
from the list and true is returned.
Uncomment the commented-out part in main() that reads a second input line and removes
numbers from the list. Test in develop mode to ensure that insertion and removal both work
properly, then submit code for grading. Ex: If input is
then output is:
Main.cpp
#include <iostream>
#include <string>
#include <vector>
#include "Node.h"
#include "SortedNumberList.h"
using namespace std;
void PrintList(SortedNumberList& list);
vector<string> SpaceSplit(string source);
int main(int argc, char *argv[]) {
// Read the line of input numbers
string inputLine;
getline(cin, inputLine);
// Split on space character
vector<string> terms = SpaceSplit(inputLine);
// Insert each value and show the sorted list's contents after each insertion
SortedNumberList list;
for (auto term : terms) {
double number = stod(term);
cout << "List after inserting " << number << ": " << endl;
list.Insert(number);
PrintList(list);
}
/*
// Read the input line with numbers to remove
getline(cin, inputLine);
terms = SpaceSplit(inputLine);
// Remove each value
for (auto term : terms) {
double number = stod(term);
cout << "List after removing " << number << ": " << endl;
list.Remove(number);
PrintList(list);
}
*/
return 0;
}
// Prints the SortedNumberList's contents, in order from head to tail
void PrintList(SortedNumberList& list) {
Node* node = list.head;
while (node) {
cout << node->GetData() << " ";
node = node->GetNext();
}
cout << endl;
}
// Splits a string at each space character, adding each substring to the vector
vector<string> SpaceSplit(string source) {
vector<string> result;
size_t start = 0;
for (size_t i = 0; i < source.length(); i++) {
if (' ' == source[i]) {
result.push_back(source.substr(start, i - start));
start = i + 1;
}
}
result.push_back(source.substr(start));
return result;
}
Sortednumberlist.h
#ifndef SORTEDNUMBERLIST_H
#define SORTEDNUMBERLIST_H
#include "Node.h"
class SortedNumberList {
private:
// Optional: Add any desired private functions here
public:
Node* head;
Node* tail;
SortedNumberList() {
head = nullptr;
tail = nullptr;
}
// Inserts the number into the list in the correct position such that the
// list remains sorted in ascending order.
void Insert(double number) {
// Your code here
}
// Removes the node with the specified number value from the list. Returns
// true if the node is found and removed, false otherwise.
bool Remove(double number) {
// Your code here (remove placeholder line below)
return false;
}
};
#endif
Node.h
#ifndef NODE_H
#define NODE_H
class Node {
protected:
double data;
Node* next;
Node* previous;
public:
// Constructs this node with the specified numerical data value. The next
// and previous pointers are each assigned nullptr.
Node(double initialData) {
data = initialData;
next = nullptr;
previous = nullptr;
}
// Constructs this node with the specified numerical data value, next
// pointer, and previous pointer.
Node(double initialData, Node* nextNode, Node* previousNode) {
data = initialData;
next = nextNode;
previous = previousNode;
}
virtual ~Node() {
}
// Returns this node's data.
virtual double GetData() {
return data;
}
// Sets this node's data.
virtual void SetData(double newData) {
data = newData;
}
// Gets this node's next pointer.
virtual Node* GetNext() {
return next;
}
// Sets this node's next pointer.
virtual void SetNext(Node* newNext) {
next = newNext;
}
// Gets this node's previous pointer.
virtual Node* GetPrevious() {
return previous;
}
// Sets this node's previous pointer.
virtual void SetPrevious(Node* newPrevious) {
previous = newPrevious;
}
};
#endif
Need to be done in C++  Please   Sorted number list implementation wit.pdf

More Related Content

Similar to Need to be done in C++ Please Sorted number list implementation wit.pdf

C++ code, please help! Troubleshooting and cannot for the life of me.pdf
C++ code, please help! Troubleshooting and cannot for the life of me.pdfC++ code, please help! Troubleshooting and cannot for the life of me.pdf
C++ code, please help! Troubleshooting and cannot for the life of me.pdfrahulfancycorner21
 
C++ Please test your program before you submit the answer.pdf
C++ Please test your program before you submit the answer.pdfC++ Please test your program before you submit the answer.pdf
C++ Please test your program before you submit the answer.pdfaashisha5
 
C++ Background Circular Linked List A circular linked list.pdf
C++ Background Circular Linked List A circular linked list.pdfC++ Background Circular Linked List A circular linked list.pdf
C++ Background Circular Linked List A circular linked list.pdfsaradashata
 
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.pdfcallawaycorb73779
 
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdfAssignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdfformicreation
 
Background Circular Linked List A circular linked list is .pdf
Background Circular Linked List A circular linked list is .pdfBackground Circular Linked List A circular linked list is .pdf
Background Circular Linked List A circular linked list is .pdfaaseletronics2013
 
Java: Introduction to Arrays
Java: Introduction to ArraysJava: Introduction to Arrays
Java: Introduction to ArraysTareq Hasan
 
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.docxBrianGHiNewmanv
 
you will implement some sorting algorithms for arrays and linked lis.pdf
you will implement some sorting algorithms for arrays and linked lis.pdfyou will implement some sorting algorithms for arrays and linked lis.pdf
you will implement some sorting algorithms for arrays and linked lis.pdfclearvisioneyecareno
 
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdfAssignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdffortmdu
 
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.pdfEricvtJFraserr
 
For this homework, you will write a program to create and manipulate.pdf
For this homework, you will write a program to create and manipulate.pdfFor this homework, you will write a program to create and manipulate.pdf
For this homework, you will write a program to create and manipulate.pdfherminaherman
 
Python programming workshop
Python programming workshopPython programming workshop
Python programming workshopBAINIDA
 
hello- please dont just copy from other answers- the following is the.docx
hello- please dont just copy from other answers- the following is the.docxhello- please dont just copy from other answers- the following is the.docx
hello- please dont just copy from other answers- the following is the.docxIsaac9LjWelchq
 

Similar to Need to be done in C++ Please Sorted number list implementation wit.pdf (20)

C++ code, please help! Troubleshooting and cannot for the life of me.pdf
C++ code, please help! Troubleshooting and cannot for the life of me.pdfC++ code, please help! Troubleshooting and cannot for the life of me.pdf
C++ code, please help! Troubleshooting and cannot for the life of me.pdf
 
C++ Please test your program before you submit the answer.pdf
C++ Please test your program before you submit the answer.pdfC++ Please test your program before you submit the answer.pdf
C++ Please test your program before you submit the answer.pdf
 
C++ Background Circular Linked List A circular linked list.pdf
C++ Background Circular Linked List A circular linked list.pdfC++ Background Circular Linked List A circular linked list.pdf
C++ Background Circular Linked List A circular linked list.pdf
 
C Exam Help
C Exam Help C Exam Help
C Exam Help
 
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
 
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdfAssignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
 
Background Circular Linked List A circular linked list is .pdf
Background Circular Linked List A circular linked list is .pdfBackground Circular Linked List A circular linked list is .pdf
Background Circular Linked List A circular linked list is .pdf
 
Java: Introduction to Arrays
Java: Introduction to ArraysJava: Introduction to Arrays
Java: Introduction to Arrays
 
17 linkedlist (1)
17 linkedlist (1)17 linkedlist (1)
17 linkedlist (1)
 
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
 
you will implement some sorting algorithms for arrays and linked lis.pdf
you will implement some sorting algorithms for arrays and linked lis.pdfyou will implement some sorting algorithms for arrays and linked lis.pdf
you will implement some sorting algorithms for arrays and linked lis.pdf
 
Array
ArrayArray
Array
 
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdfAssignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
 
dynamicList.ppt
dynamicList.pptdynamicList.ppt
dynamicList.ppt
 
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
 
For this homework, you will write a program to create and manipulate.pdf
For this homework, you will write a program to create and manipulate.pdfFor this homework, you will write a program to create and manipulate.pdf
For this homework, you will write a program to create and manipulate.pdf
 
Python programming workshop
Python programming workshopPython programming workshop
Python programming workshop
 
Python list
Python listPython list
Python list
 
hello- please dont just copy from other answers- the following is the.docx
hello- please dont just copy from other answers- the following is the.docxhello- please dont just copy from other answers- the following is the.docx
hello- please dont just copy from other answers- the following is the.docx
 
Lecture 9
Lecture 9Lecture 9
Lecture 9
 

More from aathiauto

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

More from aathiauto (20)

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

Recently uploaded

Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 

Recently uploaded (20)

Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 

Need to be done in C++ Please Sorted number list implementation wit.pdf

  • 1. Need to be done in C++ Please Sorted number list implementation with linked lists Step 1: Inspect the Node.h file Inspect the class declaration for a doubly-linked list node in Node.h. Access Node.h by clicking on the orange arrow next to main.cpp at the top of the coding window. The Node class has three member variables: a double data value, a pointer to the next node, and a pointer to the previous node. Each member variable is protected. So code outside of the class must use the provided getter and setter member functions to get or set a member variable. Node.h is read only, since no changes are required. Step 2: Implement the Insert() member function A class for a sorted, doubly-linked list is declared in SortedNumberList.h. Implement the SortedNumberList class's Insert() member function. The function must create a new node with the parameter value, then insert the node into the proper sorted position in the linked list. Ex: Suppose a SortedNumberList's current list is 23 47.25 86, then Insert(33.5) is called. A new node with data value 33.5 is created and inserted between 23 and 47.25, thus preserving the list's sorted order and yielding: 23 35.5 47.25 86 Step 3: Test in develop mode Code in main() takes a space-separated list of numbers and inserts each into a SortedNumberList. The list is displayed after each insertion. Ex: If input is then output is: Try various program inputs, ensuring that each outputs a sorted list. Step 4: Implement the Remove() member function Implement the SortedNumberList class's Remove() member function. The function takes a parameter for the number to be removed from the list. If the number does not exist in the list, the list is not changed and false is returned. Otherwise, the first instance of the number is removed from the list and true is returned.
  • 2. Uncomment the commented-out part in main() that reads a second input line and removes numbers from the list. Test in develop mode to ensure that insertion and removal both work properly, then submit code for grading. Ex: If input is then output is: Main.cpp #include <iostream> #include <string> #include <vector> #include "Node.h" #include "SortedNumberList.h" using namespace std; void PrintList(SortedNumberList& list); vector<string> SpaceSplit(string source); int main(int argc, char *argv[]) { // Read the line of input numbers string inputLine; getline(cin, inputLine); // Split on space character vector<string> terms = SpaceSplit(inputLine); // Insert each value and show the sorted list's contents after each insertion SortedNumberList list; for (auto term : terms) { double number = stod(term); cout << "List after inserting " << number << ": " << endl; list.Insert(number); PrintList(list); } /* // Read the input line with numbers to remove getline(cin, inputLine); terms = SpaceSplit(inputLine); // Remove each value for (auto term : terms) { double number = stod(term); cout << "List after removing " << number << ": " << endl; list.Remove(number); PrintList(list);
  • 3. } */ return 0; } // Prints the SortedNumberList's contents, in order from head to tail void PrintList(SortedNumberList& list) { Node* node = list.head; while (node) { cout << node->GetData() << " "; node = node->GetNext(); } cout << endl; } // Splits a string at each space character, adding each substring to the vector vector<string> SpaceSplit(string source) { vector<string> result; size_t start = 0; for (size_t i = 0; i < source.length(); i++) { if (' ' == source[i]) { result.push_back(source.substr(start, i - start)); start = i + 1; } } result.push_back(source.substr(start)); return result; } Sortednumberlist.h #ifndef SORTEDNUMBERLIST_H #define SORTEDNUMBERLIST_H #include "Node.h" class SortedNumberList { private: // Optional: Add any desired private functions here public: Node* head; Node* tail; SortedNumberList() { head = nullptr;
  • 4. tail = nullptr; } // Inserts the number into the list in the correct position such that the // list remains sorted in ascending order. void Insert(double number) { // Your code here } // Removes the node with the specified number value from the list. Returns // true if the node is found and removed, false otherwise. bool Remove(double number) { // Your code here (remove placeholder line below) return false; } }; #endif Node.h #ifndef NODE_H #define NODE_H class Node { protected: double data; Node* next; Node* previous; public: // Constructs this node with the specified numerical data value. The next // and previous pointers are each assigned nullptr. Node(double initialData) { data = initialData; next = nullptr; previous = nullptr; } // Constructs this node with the specified numerical data value, next // pointer, and previous pointer. Node(double initialData, Node* nextNode, Node* previousNode) { data = initialData; next = nextNode; previous = previousNode; }
  • 5. virtual ~Node() { } // Returns this node's data. virtual double GetData() { return data; } // Sets this node's data. virtual void SetData(double newData) { data = newData; } // Gets this node's next pointer. virtual Node* GetNext() { return next; } // Sets this node's next pointer. virtual void SetNext(Node* newNext) { next = newNext; } // Gets this node's previous pointer. virtual Node* GetPrevious() { return previous; } // Sets this node's previous pointer. virtual void SetPrevious(Node* newPrevious) { previous = newPrevious; } }; #endif