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 with.pdf

More Related Content

Similar to Need to be done in C Please Sorted number list implementation with.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.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
 
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
 
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
 
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
 
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
 
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
 
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
 
Please solve the following problem using C++- Thank you Instructions-.docx
Please solve the following problem using C++- Thank you Instructions-.docxPlease solve the following problem using C++- Thank you Instructions-.docx
Please solve the following problem using C++- Thank you Instructions-.docxPeterlqELawrenceb
 

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

Array Cont
Array ContArray Cont
Array Cont
 
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++ 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
 
C Exam Help
C Exam Help C Exam Help
C Exam Help
 
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
 
17 linkedlist (1)
17 linkedlist (1)17 linkedlist (1)
17 linkedlist (1)
 
Java: Introduction to Arrays
Java: Introduction to ArraysJava: Introduction to Arrays
Java: Introduction to Arrays
 
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
 
Array
ArrayArray
Array
 
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
 
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
 
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
 
Lecture 9
Lecture 9Lecture 9
Lecture 9
 
Python programming workshop
Python programming workshopPython programming workshop
Python programming workshop
 
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
 
Please solve the following problem using C++- Thank you Instructions-.docx
Please solve the following problem using C++- Thank you Instructions-.docxPlease solve the following problem using C++- Thank you Instructions-.docx
Please solve the following problem using C++- Thank you Instructions-.docx
 

More from aathmaproducts

Kyle- a single taxpayer- worked as a freelance software engineer for t.pdf
Kyle- a single taxpayer- worked as a freelance software engineer for t.pdfKyle- a single taxpayer- worked as a freelance software engineer for t.pdf
Kyle- a single taxpayer- worked as a freelance software engineer for t.pdfaathmaproducts
 
Introduction Inline CSS Styles are used to change the appearance of on.pdf
Introduction Inline CSS Styles are used to change the appearance of on.pdfIntroduction Inline CSS Styles are used to change the appearance of on.pdf
Introduction Inline CSS Styles are used to change the appearance of on.pdfaathmaproducts
 
If a population has a standard deviation of 5- what is the VARIANCE of.pdf
If a population has a standard deviation of 5- what is the VARIANCE of.pdfIf a population has a standard deviation of 5- what is the VARIANCE of.pdf
If a population has a standard deviation of 5- what is the VARIANCE of.pdfaathmaproducts
 
All shares were sold for $10 each- No dividends have been declared sin.pdf
All shares were sold for $10 each- No dividends have been declared sin.pdfAll shares were sold for $10 each- No dividends have been declared sin.pdf
All shares were sold for $10 each- No dividends have been declared sin.pdfaathmaproducts
 
For a standard normal distribution- find c if P(z-c)-0-1408.pdf
For a standard normal distribution- find c if P(z-c)-0-1408.pdfFor a standard normal distribution- find c if P(z-c)-0-1408.pdf
For a standard normal distribution- find c if P(z-c)-0-1408.pdfaathmaproducts
 
6- With regards to TWO of the management accounting terms listed below.pdf
6- With regards to TWO of the management accounting terms listed below.pdf6- With regards to TWO of the management accounting terms listed below.pdf
6- With regards to TWO of the management accounting terms listed below.pdfaathmaproducts
 
2----4-0 For the past several months- per capita output has decreased.pdf
2----4-0 For the past several months- per capita output has decreased.pdf2----4-0 For the past several months- per capita output has decreased.pdf
2----4-0 For the past several months- per capita output has decreased.pdfaathmaproducts
 
You are to draw cistercian number at the centre of canvas- The numbers.pdf
You are to draw cistercian number at the centre of canvas- The numbers.pdfYou are to draw cistercian number at the centre of canvas- The numbers.pdf
You are to draw cistercian number at the centre of canvas- The numbers.pdfaathmaproducts
 
Using Coca-Cola- access its most recent financial statements- form 10-.pdf
Using Coca-Cola- access its most recent financial statements- form 10-.pdfUsing Coca-Cola- access its most recent financial statements- form 10-.pdf
Using Coca-Cola- access its most recent financial statements- form 10-.pdfaathmaproducts
 
Select the statements that explain why two traits would be inherited t.pdf
Select the statements that explain why two traits would be inherited t.pdfSelect the statements that explain why two traits would be inherited t.pdf
Select the statements that explain why two traits would be inherited t.pdfaathmaproducts
 
What do scientists identify as the reasons for catfish rely on the lat.pdf
What do scientists identify as the reasons for catfish rely on the lat.pdfWhat do scientists identify as the reasons for catfish rely on the lat.pdf
What do scientists identify as the reasons for catfish rely on the lat.pdfaathmaproducts
 
Refer to Table 6-2- The unemployment rate in year 3 is.pdf
Refer to Table 6-2- The unemployment rate in year 3 is.pdfRefer to Table 6-2- The unemployment rate in year 3 is.pdf
Refer to Table 6-2- The unemployment rate in year 3 is.pdfaathmaproducts
 
What steps are taken in order to run a macro on a new set of data- Mac.pdf
What steps are taken in order to run a macro on a new set of data- Mac.pdfWhat steps are taken in order to run a macro on a new set of data- Mac.pdf
What steps are taken in order to run a macro on a new set of data- Mac.pdfaathmaproducts
 
1- Define Sex 2- Can you be in a roman and intimate relationship witho.pdf
1- Define Sex 2- Can you be in a roman and intimate relationship witho.pdf1- Define Sex 2- Can you be in a roman and intimate relationship witho.pdf
1- Define Sex 2- Can you be in a roman and intimate relationship witho.pdfaathmaproducts
 
Which of the following is a typical activity performed during the Anal.pdf
Which of the following is a typical activity performed during the Anal.pdfWhich of the following is a typical activity performed during the Anal.pdf
Which of the following is a typical activity performed during the Anal.pdfaathmaproducts
 
1- Picaresque Sails Co- has total assets of $140-000 and total liabili.pdf
1- Picaresque Sails Co- has total assets of $140-000 and total liabili.pdf1- Picaresque Sails Co- has total assets of $140-000 and total liabili.pdf
1- Picaresque Sails Co- has total assets of $140-000 and total liabili.pdfaathmaproducts
 
The m and p genes are 14 m-u- apart on an autosome- An Mp-mP woman mat.pdf
The m and p genes are 14 m-u- apart on an autosome- An Mp-mP woman mat.pdfThe m and p genes are 14 m-u- apart on an autosome- An Mp-mP woman mat.pdf
The m and p genes are 14 m-u- apart on an autosome- An Mp-mP woman mat.pdfaathmaproducts
 
QUIZ3 The number of months brand A paint lasted before fading was 10-6.pdf
QUIZ3 The number of months brand A paint lasted before fading was 10-6.pdfQUIZ3 The number of months brand A paint lasted before fading was 10-6.pdf
QUIZ3 The number of months brand A paint lasted before fading was 10-6.pdfaathmaproducts
 
place distribution-promotion of urban outfitters Design distribution s.pdf
place distribution-promotion of urban outfitters Design distribution s.pdfplace distribution-promotion of urban outfitters Design distribution s.pdf
place distribution-promotion of urban outfitters Design distribution s.pdfaathmaproducts
 
Prove that L(NFA) is countable-.pdf
Prove that L(NFA) is countable-.pdfProve that L(NFA) is countable-.pdf
Prove that L(NFA) is countable-.pdfaathmaproducts
 

More from aathmaproducts (20)

Kyle- a single taxpayer- worked as a freelance software engineer for t.pdf
Kyle- a single taxpayer- worked as a freelance software engineer for t.pdfKyle- a single taxpayer- worked as a freelance software engineer for t.pdf
Kyle- a single taxpayer- worked as a freelance software engineer for t.pdf
 
Introduction Inline CSS Styles are used to change the appearance of on.pdf
Introduction Inline CSS Styles are used to change the appearance of on.pdfIntroduction Inline CSS Styles are used to change the appearance of on.pdf
Introduction Inline CSS Styles are used to change the appearance of on.pdf
 
If a population has a standard deviation of 5- what is the VARIANCE of.pdf
If a population has a standard deviation of 5- what is the VARIANCE of.pdfIf a population has a standard deviation of 5- what is the VARIANCE of.pdf
If a population has a standard deviation of 5- what is the VARIANCE of.pdf
 
All shares were sold for $10 each- No dividends have been declared sin.pdf
All shares were sold for $10 each- No dividends have been declared sin.pdfAll shares were sold for $10 each- No dividends have been declared sin.pdf
All shares were sold for $10 each- No dividends have been declared sin.pdf
 
For a standard normal distribution- find c if P(z-c)-0-1408.pdf
For a standard normal distribution- find c if P(z-c)-0-1408.pdfFor a standard normal distribution- find c if P(z-c)-0-1408.pdf
For a standard normal distribution- find c if P(z-c)-0-1408.pdf
 
6- With regards to TWO of the management accounting terms listed below.pdf
6- With regards to TWO of the management accounting terms listed below.pdf6- With regards to TWO of the management accounting terms listed below.pdf
6- With regards to TWO of the management accounting terms listed below.pdf
 
2----4-0 For the past several months- per capita output has decreased.pdf
2----4-0 For the past several months- per capita output has decreased.pdf2----4-0 For the past several months- per capita output has decreased.pdf
2----4-0 For the past several months- per capita output has decreased.pdf
 
You are to draw cistercian number at the centre of canvas- The numbers.pdf
You are to draw cistercian number at the centre of canvas- The numbers.pdfYou are to draw cistercian number at the centre of canvas- The numbers.pdf
You are to draw cistercian number at the centre of canvas- The numbers.pdf
 
Using Coca-Cola- access its most recent financial statements- form 10-.pdf
Using Coca-Cola- access its most recent financial statements- form 10-.pdfUsing Coca-Cola- access its most recent financial statements- form 10-.pdf
Using Coca-Cola- access its most recent financial statements- form 10-.pdf
 
Select the statements that explain why two traits would be inherited t.pdf
Select the statements that explain why two traits would be inherited t.pdfSelect the statements that explain why two traits would be inherited t.pdf
Select the statements that explain why two traits would be inherited t.pdf
 
What do scientists identify as the reasons for catfish rely on the lat.pdf
What do scientists identify as the reasons for catfish rely on the lat.pdfWhat do scientists identify as the reasons for catfish rely on the lat.pdf
What do scientists identify as the reasons for catfish rely on the lat.pdf
 
Refer to Table 6-2- The unemployment rate in year 3 is.pdf
Refer to Table 6-2- The unemployment rate in year 3 is.pdfRefer to Table 6-2- The unemployment rate in year 3 is.pdf
Refer to Table 6-2- The unemployment rate in year 3 is.pdf
 
What steps are taken in order to run a macro on a new set of data- Mac.pdf
What steps are taken in order to run a macro on a new set of data- Mac.pdfWhat steps are taken in order to run a macro on a new set of data- Mac.pdf
What steps are taken in order to run a macro on a new set of data- Mac.pdf
 
1- Define Sex 2- Can you be in a roman and intimate relationship witho.pdf
1- Define Sex 2- Can you be in a roman and intimate relationship witho.pdf1- Define Sex 2- Can you be in a roman and intimate relationship witho.pdf
1- Define Sex 2- Can you be in a roman and intimate relationship witho.pdf
 
Which of the following is a typical activity performed during the Anal.pdf
Which of the following is a typical activity performed during the Anal.pdfWhich of the following is a typical activity performed during the Anal.pdf
Which of the following is a typical activity performed during the Anal.pdf
 
1- Picaresque Sails Co- has total assets of $140-000 and total liabili.pdf
1- Picaresque Sails Co- has total assets of $140-000 and total liabili.pdf1- Picaresque Sails Co- has total assets of $140-000 and total liabili.pdf
1- Picaresque Sails Co- has total assets of $140-000 and total liabili.pdf
 
The m and p genes are 14 m-u- apart on an autosome- An Mp-mP woman mat.pdf
The m and p genes are 14 m-u- apart on an autosome- An Mp-mP woman mat.pdfThe m and p genes are 14 m-u- apart on an autosome- An Mp-mP woman mat.pdf
The m and p genes are 14 m-u- apart on an autosome- An Mp-mP woman mat.pdf
 
QUIZ3 The number of months brand A paint lasted before fading was 10-6.pdf
QUIZ3 The number of months brand A paint lasted before fading was 10-6.pdfQUIZ3 The number of months brand A paint lasted before fading was 10-6.pdf
QUIZ3 The number of months brand A paint lasted before fading was 10-6.pdf
 
place distribution-promotion of urban outfitters Design distribution s.pdf
place distribution-promotion of urban outfitters Design distribution s.pdfplace distribution-promotion of urban outfitters Design distribution s.pdf
place distribution-promotion of urban outfitters Design distribution s.pdf
 
Prove that L(NFA) is countable-.pdf
Prove that L(NFA) is countable-.pdfProve that L(NFA) is countable-.pdf
Prove that L(NFA) is countable-.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
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
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
 
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
 
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
 
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
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
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
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
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
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 

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
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
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
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
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...
 
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
 
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
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
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
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
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
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
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
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.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)
 

Need to be done in C Please Sorted number list implementation with.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