SlideShare a Scribd company logo
In C++ please, do not alter node.h
Step 1: Inspect the Node.h file
Inspect the class declaration for a doubly-linked list node in Node.h. 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
77 15 -42 63.5
then output is:
List after inserting 77:
77 List after inserting 15:
15 77
List after inserting -42:
-42 15 77
List after inserting 63.5:
-42 15 63.5 77
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
84 72 19 61 19 84
then output is:
List after inserting 84:
84
List after inserting 72:
72 84
List after inserting 19:
19 72 84
List after inserting 61:
19 61 72 84
List after removing 19:
61 72 84
List after removing 84:
61 72
Code below:
main.cpp
#include
#include
#include
#include "Node.h"
#include "SortedNumberList.h"
using namespace std;
void PrintList(SortedNumberList& list);
vector 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 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 SpaceSplit(string source) {
vector 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;
}
Node.h (no change)
#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
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

More Related Content

PDF
Need to be done in C++ Please Sorted number list implementation wit.pdf
PDF
Need to be done in C Please Sorted number list implementation with.pdf
PDF
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
PDF
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
PDF
Please help solve this in C++ So the program is working fin.pdf
PDF
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
PDF
Complete a C++ class implementation for a linked-list of sorted (asc.pdf
DOCX
Linked lists
Need to be done in C++ Please Sorted number list implementation wit.pdf
Need to be done in C Please Sorted number list implementation with.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
Please help solve this in C++ So the program is working fin.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Complete a C++ class implementation for a linked-list of sorted (asc.pdf
Linked lists

Similar to In C++ please, do not alter node.hStep 1 Inspect the Node.h file.pdf (20)

PDF
This assignment and the next (#5) involve design and development of a.pdf
PDF
In C++Write a recursive function to determine whether or not a Lin.pdf
PDF
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
PDF
Sorted number list implementation with linked listsStep 1 Inspec.pdf
PDF
Homework 05 - Linked Lists (C++)(1) Implement the concepts of a un.pdf
PDF
Consider a double-linked linked list implementation with the followin.pdf
PDF
In the class we extensively discussed a node class called IntNode in.pdf
PDF
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
PDF
–PLS write program in c++Recursive Linked List OperationsWrite a.pdf
PDF
I need help completing this C++ code with these requirements.instr.pdf
PDF
Data Structures in C++I am really new to C++, so links are really .pdf
PPTX
C Homework Help
PPTX
Linked lists in Data Structure
PDF
Lec-4_Linked-List (1).pdf
PDF
Using the C++ programming language1. Implement the UnsortedList cl.pdf
DOCX
CS 107 – Introduction to Computing and Programming – Spring 20.docx
PDF
Merge Sort implementation in C++ The implementation for Mergesort gi.pdf
PDF
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
PPTX
3.linked list
PPTX
C Exam Help
This assignment and the next (#5) involve design and development of a.pdf
In C++Write a recursive function to determine whether or not a Lin.pdf
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
Sorted number list implementation with linked listsStep 1 Inspec.pdf
Homework 05 - Linked Lists (C++)(1) Implement the concepts of a un.pdf
Consider a double-linked linked list implementation with the followin.pdf
In the class we extensively discussed a node class called IntNode in.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
–PLS write program in c++Recursive Linked List OperationsWrite a.pdf
I need help completing this C++ code with these requirements.instr.pdf
Data Structures in C++I am really new to C++, so links are really .pdf
C Homework Help
Linked lists in Data Structure
Lec-4_Linked-List (1).pdf
Using the C++ programming language1. Implement the UnsortedList cl.pdf
CS 107 – Introduction to Computing and Programming – Spring 20.docx
Merge Sort implementation in C++ The implementation for Mergesort gi.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
3.linked list
C Exam Help
Ad

More from stopgolook (15)

PDF
Jordano Food Products Supply Chain Profile Jordano Foods Tracie Shan.pdf
PDF
Java Code The traditional way to deal with these in Parsers is the .pdf
PDF
Javai have to make a method that takes a linked list and then retu.pdf
PDF
J.M. Baker worked as a traditional land use researcher and consultan.pdf
PDF
IT Project Management homework Identify any project of your choice.pdf
PDF
INSTRUCTIONSDevelop, and present a plan and business case for an a.pdf
PDF
In the realm of professional dynamics, understanding and appreciating .pdf
PDF
import React, { useEffect } from react;import { BrowserRouter as.pdf
PDF
Im trying to define a class in java but I seem to be having a bit o.pdf
PDF
in c languageTo determine the maximum string length, we need to .pdf
PDF
In 2011, the head of the Presidential Protection Force (for purposes.pdf
PDF
import java.util.Scanner;public class Main {private static i.pdf
PDF
If a taxpayer has investment income that exceeds a certain threshold.pdf
PDF
Im having an issue with the simulateOPT() methodthis is the p.pdf
PDF
I. Naive Robot Navigation ProblemDesign a program that uses the B.pdf
Jordano Food Products Supply Chain Profile Jordano Foods Tracie Shan.pdf
Java Code The traditional way to deal with these in Parsers is the .pdf
Javai have to make a method that takes a linked list and then retu.pdf
J.M. Baker worked as a traditional land use researcher and consultan.pdf
IT Project Management homework Identify any project of your choice.pdf
INSTRUCTIONSDevelop, and present a plan and business case for an a.pdf
In the realm of professional dynamics, understanding and appreciating .pdf
import React, { useEffect } from react;import { BrowserRouter as.pdf
Im trying to define a class in java but I seem to be having a bit o.pdf
in c languageTo determine the maximum string length, we need to .pdf
In 2011, the head of the Presidential Protection Force (for purposes.pdf
import java.util.Scanner;public class Main {private static i.pdf
If a taxpayer has investment income that exceeds a certain threshold.pdf
Im having an issue with the simulateOPT() methodthis is the p.pdf
I. Naive Robot Navigation ProblemDesign a program that uses the B.pdf
Ad

Recently uploaded (20)

PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Complications of Minimal Access Surgery at WLH
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
GDM (1) (1).pptx small presentation for students
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
Lesson notes of climatology university.
PDF
Classroom Observation Tools for Teachers
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
Cell Structure & Organelles in detailed.
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Computing-Curriculum for Schools in Ghana
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Microbial diseases, their pathogenesis and prophylaxis
human mycosis Human fungal infections are called human mycosis..pptx
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Abdominal Access Techniques with Prof. Dr. R K Mishra
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPH.pptx obstetrics and gynecology in nursing
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Complications of Minimal Access Surgery at WLH
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
GDM (1) (1).pptx small presentation for students
Module 4: Burden of Disease Tutorial Slides S2 2025
Lesson notes of climatology university.
Classroom Observation Tools for Teachers
Microbial disease of the cardiovascular and lymphatic systems
Cell Structure & Organelles in detailed.
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Computing-Curriculum for Schools in Ghana
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Pharmacology of Heart Failure /Pharmacotherapy of CHF

In C++ please, do not alter node.hStep 1 Inspect the Node.h file.pdf

  • 1. In C++ please, do not alter node.h Step 1: Inspect the Node.h file Inspect the class declaration for a doubly-linked list node in Node.h. 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 77 15 -42 63.5 then output is: List after inserting 77: 77 List after inserting 15: 15 77 List after inserting -42: -42 15 77 List after inserting 63.5: -42 15 63.5 77 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 84 72 19 61 19 84 then output is: List after inserting 84: 84 List after inserting 72: 72 84 List after inserting 19: 19 72 84 List after inserting 61: 19 61 72 84 List after removing 19: 61 72 84 List after removing 84: 61 72 Code below: main.cpp #include #include #include #include "Node.h" #include "SortedNumberList.h" using namespace std; void PrintList(SortedNumberList& list); vector 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 terms = SpaceSplit(inputLine); // Insert each value and show the sorted list's contents after each insertion SortedNumberList list;
  • 3. 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 SpaceSplit(string source) { vector 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));
  • 4. start = i + 1; } } result.push_back(source.substr(start)); return result; } Node.h (no change) #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; }
  • 5. // 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 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;
  • 6. } // 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