SlideShare a Scribd company logo
1 of 20
Download to read offline
C++ problem
Part 1: Recursive Print (40 pts)
Please write the recursive List reverse print function, whose iterative version we wrote in class.
Below are the function signatures for the functions you are going to need:
public:
/**Additional Operations*/
void print_reverse();
//Wrapper function that calls the reverse helper function to print a list in reverse
//prints nothing if the List is empty
private:
void reverse(Nodeptr node);
//Helper function for the public printReverse() function.
//Recursively prints the data in a List in reverse.
Why do we need the private helper function here?
Since we are going to be reversing our list node by node, in a recursive fashion, we want to pass
a one node at a time to our reverse function.
However, since our nodes are private, we cannot access them if we call the function inside of
main.
Add these function signatures to your List.h file along with your other function prototypes inside
the class definition.
Make sure that you place the reverse function inside the private portion of your List class
definition and the print_reverse function prototype to the public portion of your List class
definition.
Now, implement these two functions inside of List.h, under your section for additional
operations.
Important: Test each function carefully inside of your ListTest.cpp to make sure that it is
working properly.
Part 2: Adding an Index to Your List Nodes (20 pts)
Next, you will add the following functions to your List.h
/**Accessor Functions*/
int get_index();
//Indicates the index of the Node where the iterator is currently pointing
//Nodes are numbered from 1 to length of the list
//Pre: length != 0
//Pre: !off_end()
...
int List::get_index()
{
//Implement the function here
}
/**Manipulation Procedures*/
void scroll_to_index(int index);
//Moves the iterator to the node whose index is specified by the user
//Pre: length != 0
...
void scroll_to_index(int index)
{
//Implement function here
}
Part 3: Implementing Search as Part of Your List (40 pts)
Now, we are going to add two search functions to our List so that we can search for elements in
our List.
The first of these functions is going to be a simple linear search function.
You will need to add the following function prototype and function definition to your List.h:
/**Additional Operations*/
int linear_search(listitem item);
//Searchs the list, element by element, from the start of the List to the end of the List
//Returns the index of the element, if it is found in the List
//Returns -1 if the element is not in the List
//Pre: length != 0
...
int List::linear_search(listitem item)
{
//Implement the function here
}
You are also going to add a function to perform recursive binary search on your List.
You will need to add the following function prototype and function definition to your List.h:
int binary_search(int low, int high, listitem item);
//Recursively searchs the list by dividing the search space in half
//Returns the index of the element, if it is found in the List
//Returns -1 if the element is not in the List
//Pre: length != 0
//Pre: List is sorted (must test on a sorted list)
...
int List::binary_search(int low, int high, listitem item)
{
//Implement the function here
}
Important: For credit, you must implement the recursive version of binary search.
This is my current List.h file:
#ifndef LIST_H_
#include //for NULL
#include
#include
#include
using namespace std;
template
class List {
private:
struct Node {
listitem data;
Node* next;
Node* previous;
Node(listitem data) :
next(NULL), previous(NULL), data(data) {
}
};
typedef struct Node* NodePtr;
NodePtr start;
NodePtr end;
NodePtr cursor;
int length;
void reverse(NodePtr node);
//Helper function for the public printReverse() function.
//Recursively prints the data in a List in reverse.
public:
/**Constructors and Destructors*/
List();
//Default constructor; initializes and empty list
//Postcondition: list is initialized or is empty
~List();
//Destructor. Frees memory allocated to the list
//Postcondition: Memory in the list is deleted
List(const List &list);
//Copy construcor. Initializes list to have the same elements as another list
//Postcondition: Other lists have same elements as the main list
/**Accessors*/
listitem get_start();
//Returns the first element in the list
//Precondition: first element must not be empty
listitem get_end();
//Returns the last element in the list
//Precondition: last element must not be empty
listitem get_cursor();
//Returns the element pointed to by the iterator
//Precondition: the element pointed to by the iterator must not be empty
bool is_empty();
//Determines whether a list is empty.
bool off_end();
//Determines if the iterator is off the end of the list (i.e. whether cursor is NULL)
int get_length();
//Returns the length of the list
/**Manipulation Procedures*/
void begin_cursor();
//Moves the iterator to point to the first element in the list
//If the list is empty, the iterator remains NULL
//Postcondition: the iterator point to the first element in the list
void add_cursor(listitem data);
//Inserts a new element into the list in the position after the iterator
//Precondition: the iterator must point to an element
//Postcondition: a new element is inserted in the position after the iterator
void remove_end();
//Removes the value of the last element in the list
//Precondition: last element is not a null object
//Postcondition: the the value of the last element in the list is removed
void remove_start();
//Removes the value of the first element in the list
//Precondition: first element is not a null object
//Postcondition: the value of the first element in the list is removed
void add_end(listitem data);
//Inserts a new element at the end of the list
//If the list is empty, the new element becomes both start and end
//Postcondition: a new element is inserted at the end of the list
void add_start(listitem data);
//Inserts a new element at the start of the list
//If the list is empty, the new element becomes both start and end
//Postcondition: a new element is inserted at the start of the list
void remove_cursor();
//Removes the element pointed at by the iterator
//Precondition: the element pointed at by the iterator is not a null object
//Postcondition: the element pointed at by the iterator is removed
void move_cursor();
//Moves the iterator forward by one element in the list
//Precondition: the next element is not a null object
//Postcondition: the iterator moves forward by one element in the list
/**Additional List Operations*/
void print();
//Prints to the console the value of each element in the list sequentially
//and separated by a blank space
//Prints nothing if the list is empty
bool operator==(const List &list);
//Tests two lists to determine whether their contents are equal
//Postcondition: returns true if lists are equal and false otherwise
/**Additional Operations*/
void print_reverse();
//Wrapper function that calls the reverse helper function to print a list in reverse
//prints nothing if the List is empty
};
template
List::List() :
start(NULL), end(NULL), cursor(NULL), length(0) {
}
template
List::~List() {
cursor = start;
NodePtr temp;
while (cursor != NULL) {
temp = cursor->next;
delete cursor;
cursor = temp;
}
}
template
List::List(const List &list) :
length(list.length) {
if (list.start == NULL) //If the original list is empty, make an empty list for this list
{
start = end = cursor = NULL;
} else {
start = new Node(list.start->data); //using second Node constructor
NodePtr temp = list.start; //set a temporary node pointer to point at the start of the original
list
cursor = start; //set iterator to point to start of the new list
while (temp->next != NULL) {
temp = temp->next; //advance up to the next node in the original list
cursor->next = new Node(temp->data); //using node constructor to create a new node
with copy of data
cursor = cursor->next; //advance to this new node
}
end = cursor; //Why do I need this line of code?
cursor = NULL;
}
}
template
void List::print() {
NodePtr temp = start; //create a temporary iterator
while (temp != NULL) {
//What two lines of code go here?
cout << temp->data << " ";
temp = temp->next;
//Hint: One statement should contain a cout
}
cout << endl; //What does this do?
}
template
void List::add_start(listitem data) {
if (length == 0) //Why is this necessary?
{
start = new Node(data);
end = start;
} else {
NodePtr N = new Node(data); //create the new node by calling the node constructor
N->next = start; //set the new node's next field to point to the start
start->previous = N;
start = N; //make the start be the new node
}
length++;
}
template
void List::add_end(listitem data) {
if (length == 0) {
start = new Node(data);
end = start;
} else {
NodePtr N = new Node(data); //create the new node by calling the node constructor
end->next = N;
N->previous = end;
end = N;
}
length++;
}
template
bool List::is_empty() {
return (length == 0);
}
template
int List::get_length() {
return length;
}
template
listitem List::get_start() {
assert(start != NULL);
return start->data;
}
template
listitem List::get_end() {
assert(end != NULL);
return end->data;
}
template
void List::begin_cursor() {
cursor = start;
}
template
listitem List::get_cursor() {
assert(cursor != NULL);
return cursor->data;
}
template
void List::move_cursor() {
assert(cursor != NULL);
cursor = cursor->next;
}
template
bool List::off_end() {
return (cursor == NULL);
}
template
void List::remove_start() {
assert(length != 0);
if (length == 1) {
delete start;
start = end = cursor = NULL;
length = 0;
} else {
if (cursor == start)
cursor = NULL;
start = start->next;
delete start->previous;
start->previous = NULL;
length--;
}
}
template
void List::remove_end() {
assert(length != 0);
if (length == 1) {
delete end;
start = end = cursor = NULL;
length = 0;
} else {
if (cursor == end)
cursor = NULL;
end = end->previous;
delete end->next;
end->next = NULL;
length--;
}
}
template
void List::add_cursor(listitem data) {
assert(!off_end());
if (cursor == end) {
add_end(data);
} else {
NodePtr newNode = new Node(data);
newNode->next = cursor->next;
newNode->previous = cursor;
cursor->next->previous = newNode;
cursor->next = newNode;
length++;
}
}
template
void List::remove_cursor() {
assert(cursor != NULL);
if (cursor == start) {
remove_start();
} else if (cursor == end) {
remove_end();
} else {
cursor->previous->next = cursor->next;
cursor->next->previous = cursor->previous;
delete cursor;
cursor = NULL;
length--;
}
}
template
bool List::operator==(const List& list) {
if (length != list.length)
return false;
NodePtr temp1 = start;
NodePtr temp2 = list.start;
while (temp1 != NULL) {
if (temp1->data != temp2->data)
return false;
temp1 = temp1->next;
temp2 = temp2->next;
}
return true;
}
#define LIST_H_
#endif /* LIST_H_ */
Solution
Lisht.h
#include "stdafx.h"
#include
#include
using namespace std;
template
class List {
private:
struct Node {
listitem data;
Node* next;
Node* previous;
Node(listitem data) :
next(NULL), previous(NULL), data(data) {
}
};
typedef struct Node* NodePtr;
NodePtr start;
NodePtr end;
NodePtr cursor;
int length;
void reverse(NodePtr node);
public:
List();
~List();
List(const List &list);
listitem get_start();
listitem get_end();
listitem get_cursor();
bool is_empty();
bool off_end();
int get_length();
void begin_cursor();
void add_cursor(listitem data);
void remove_end();
void remove_start();
void add_end(listitem data);
void add_start(listitem data);
void remove_cursor();
void move_cursor();
void print();
bool operator==(const List &list);
// Answer
void print_reverse();
int get_index();
void scroll_to_index(int index);
int linear_search(listitem item);
int binary_search(int low, int high, listitem item);
void sort(NodePtr small);
};
List.cpp
#include "stdafx.h"
#include"List.h"
template
List::List() :
start(NULL), end(NULL), cursor(NULL), length(0)
{
}
template
List::~List() {
cursor = start;
NodePtr temp;
while (cursor != NULL) {
temp = cursor->next;
delete cursor;
cursor = temp;
}
}
template
List::List(const List &list) :
length(list.length) {
if (list.start == NULL) //If the original list is empty, make an empty list for this list
{
start = end = cursor = NULL;
}
else {
start = new Node(list.start->data); //using second Node constructor
NodePtr temp = list.start; //set a temporary node pointer to point at the start of the original list
cursor = start; //set iterator to point to start of the new list
while (temp->next != NULL) {
temp = temp->next; //advance up to the next node in the original list
cursor->next = new Node(temp->data); //using node constructor to create a new node with copy
of data
cursor = cursor->next; //advance to this new node
}
end = cursor; //Why do I need this line of code?
cursor = NULL;
}
}
template
void List::print() {
NodePtr temp = start; //create a temporary iterator
while (temp != NULL) {
//What two lines of code go here?
cout << temp->data << " ";
temp = temp->next;
//Hint: One statement should contain a cout
}
cout << endl; //What does this do?
}
template
void List::add_start(listitem data) {
if (length == 0) //Why is this necessary?
{
start = new Node(data);
end = start;
}
else {
NodePtr N = new Node(data); //create the new node by calling the node constructor
N->next = start; //set the new node's next field to point to the start
start->previous = N;
start = N; //make the start be the new node
}
length++;
}
template
void List::add_end(listitem data) {
if (length == 0) {
start = new Node(data);
end = start;
}
else {
NodePtr N = new Node(data); //create the new node by calling the node constructor
end->next = N;
N->previous = end;
end = N;
}
length++;
}
template
bool List::is_empty() {
return (length == 0);
}
template
int List::get_length() {
return length;
}
template
listitem List::get_start() {
assert(start != NULL);
return start->data;
}
template
listitem List::get_end() {
assert(end != NULL);
return end->data;
}
template
void List::begin_cursor() {
cursor = start;
}
template
listitem List::get_cursor() {
assert(cursor != NULL);
return cursor->data;
}
template
void List::move_cursor() {
assert(cursor != NULL);
cursor = cursor->next;
}
template
bool List::off_end() {
return (cursor == NULL);
}
template
void List::remove_start() {
assert(length != 0);
if (length == 1) {
delete start;
start = end = cursor = NULL;
length = 0;
}
else {
if (cursor == start)
cursor = NULL;
start = start->next;
delete start->previous;
start->previous = NULL;
length--;
}
}
template
void List::remove_end() {
assert(length != 0);
if (length == 1) {
delete end;
start = end = cursor = NULL;
length = 0;
}
else {
if (cursor == end)
cursor = NULL;
end = end->previous;
delete end->next;
end->next = NULL;
length--;
}
}
template
void List::add_cursor(listitem data) {
assert(!off_end());
if (cursor == end) {
add_end(data);
}
else {
NodePtr newNode = new Node(data);
newNode->next = cursor->next;
newNode->previous = cursor;
cursor->next->previous = newNode;
cursor->next = newNode;
length++;
}
}
template
void List::remove_cursor() {
assert(cursor != NULL);
if (cursor == start) {
remove_start();
}
else if (cursor == end) {
remove_end();
}
else {
cursor->previous->next = cursor->next;
cursor->next->previous = cursor->previous;
delete cursor;
cursor = NULL;
length--;
}
}
template
bool List::operator==(const List& list) {
if (length != list.length)
return false;
NodePtr temp1 = start;
NodePtr temp2 = list.start;
while (temp1 != NULL) {
if (temp1->data != temp2->data)
return false;
temp1 = temp1->next;
temp2 = temp2->next;
}
return true;
}
template
void List::reverse(NodePtr list)
{
if (list) {
reverse(list->next);
cout << list->data << endl;
}
}
template
void List::print_reverse()
{
reverse(start);
}
template
int List::get_index()
{
if (off_end() == true)
{
cout << "Error! Iterator is not pointing to anything..." << endl;
return 0;
}
else
{
int count = 1;
NodePtr temp = start;
while (temp != cursor)
{
count++;
temp = temp->next;
}
return count;
}
}
template
void List::scroll_to_index(int index)
{
int max = get_length();
for (int j = index; j <= max; j++)
{
get_cursor(j);
if (cursor == NULL)
cout << "Calling scroll when iterator is NULL" << endl;
else
cursor = cursor->next;
}
}
template
int List::linear_search(listitem item)
{
NodePtr temp = start;
int count = 1;
bool valFound = false;
while (temp != NULL)
{
if (temp->data == item)
{
valFound = true;
temp = NULL;
}
else
{
count++;
temp = temp->next;
}
}
if (valFound == false)
{
cout << "Error. Item not found" << endl;
return -1;
}
else
return count;
}

More Related Content

Similar to C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf

Please help solve this in C++ So the program is working fin.pdf
Please help solve this in C++ So the program is working fin.pdfPlease help solve this in C++ So the program is working fin.pdf
Please help solve this in C++ So the program is working fin.pdfankit11134
 
Using the C++ programming language1. Implement the UnsortedList cl.pdf
Using the C++ programming language1. Implement the UnsortedList cl.pdfUsing the C++ programming language1. Implement the UnsortedList cl.pdf
Using the C++ programming language1. Implement the UnsortedList cl.pdfmallik3000
 
please i need help Im writing a program to test the merge sort alg.pdf
please i need help Im writing a program to test the merge sort alg.pdfplease i need help Im writing a program to test the merge sort alg.pdf
please i need help Im writing a program to test the merge sort alg.pdfezonesolutions
 
Implement the following specification of UnsortedType using circular.pdf
Implement the following specification of UnsortedType using circular.pdfImplement the following specification of UnsortedType using circular.pdf
Implement the following specification of UnsortedType using circular.pdfudit652068
 
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdfC++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdfpoblettesedanoree498
 
Consider a double-linked linked list implementation with the followin.pdf
Consider a double-linked linked list implementation with the followin.pdfConsider a double-linked linked list implementation with the followin.pdf
Consider a double-linked linked list implementation with the followin.pdfsales98
 
Data Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdfData Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdfrohit219406
 
helpInstructionsAdd the function max as an abstract function to .pdf
helpInstructionsAdd the function max as an abstract function to .pdfhelpInstructionsAdd the function max as an abstract function to .pdf
helpInstructionsAdd the function max as an abstract function to .pdfalmonardfans
 
This class maintains a list of 4 integers. This list .docx
 This class maintains a list of 4 integers.   This list .docx This class maintains a list of 4 integers.   This list .docx
This class maintains a list of 4 integers. This list .docxKomlin1
 
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
 
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdfInspect the class declaration for a doubly-linked list node in Node-h-.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdfvishalateen
 
Complete a C++ class implementation for a linked-list of sorted (asc.pdf
Complete a C++ class implementation for a linked-list of sorted (asc.pdfComplete a C++ class implementation for a linked-list of sorted (asc.pdf
Complete a C++ class implementation for a linked-list of sorted (asc.pdfshahidqamar17
 
How do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdfHow do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdffeelinggift
 
Homework 05 - Linked Lists (C++)(1) Implement the concepts of a un.pdf
Homework 05 - Linked Lists (C++)(1) Implement the concepts of a un.pdfHomework 05 - Linked Lists (C++)(1) Implement the concepts of a un.pdf
Homework 05 - Linked Lists (C++)(1) Implement the concepts of a un.pdfezzi97
 
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdfWrite a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdfrozakashif85
 
Need Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdf
Need Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdfNeed Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdf
Need Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdfEdwardw5nSlaterl
 
Implement a function called getElements() that takes in two lists. T.pdf
Implement a function called getElements() that takes in two lists. T.pdfImplement a function called getElements() that takes in two lists. T.pdf
Implement a function called getElements() that takes in two lists. T.pdfarracollection
 
DS UNIT4_OTHER LIST STRUCTURES.docx
DS UNIT4_OTHER LIST STRUCTURES.docxDS UNIT4_OTHER LIST STRUCTURES.docx
DS UNIT4_OTHER LIST STRUCTURES.docxVeerannaKotagi1
 
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
 

Similar to C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf (20)

Please help solve this in C++ So the program is working fin.pdf
Please help solve this in C++ So the program is working fin.pdfPlease help solve this in C++ So the program is working fin.pdf
Please help solve this in C++ So the program is working fin.pdf
 
Using the C++ programming language1. Implement the UnsortedList cl.pdf
Using the C++ programming language1. Implement the UnsortedList cl.pdfUsing the C++ programming language1. Implement the UnsortedList cl.pdf
Using the C++ programming language1. Implement the UnsortedList cl.pdf
 
please i need help Im writing a program to test the merge sort alg.pdf
please i need help Im writing a program to test the merge sort alg.pdfplease i need help Im writing a program to test the merge sort alg.pdf
please i need help Im writing a program to test the merge sort alg.pdf
 
Implement the following specification of UnsortedType using circular.pdf
Implement the following specification of UnsortedType using circular.pdfImplement the following specification of UnsortedType using circular.pdf
Implement the following specification of UnsortedType using circular.pdf
 
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdfC++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
 
Consider a double-linked linked list implementation with the followin.pdf
Consider a double-linked linked list implementation with the followin.pdfConsider a double-linked linked list implementation with the followin.pdf
Consider a double-linked linked list implementation with the followin.pdf
 
Data Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdfData Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdf
 
helpInstructionsAdd the function max as an abstract function to .pdf
helpInstructionsAdd the function max as an abstract function to .pdfhelpInstructionsAdd the function max as an abstract function to .pdf
helpInstructionsAdd the function max as an abstract function to .pdf
 
This class maintains a list of 4 integers. This list .docx
 This class maintains a list of 4 integers.   This list .docx This class maintains a list of 4 integers.   This list .docx
This class maintains a list of 4 integers. This list .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
 
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdfInspect the class declaration for a doubly-linked list node in Node-h-.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
 
Complete a C++ class implementation for a linked-list of sorted (asc.pdf
Complete a C++ class implementation for a linked-list of sorted (asc.pdfComplete a C++ class implementation for a linked-list of sorted (asc.pdf
Complete a C++ class implementation for a linked-list of sorted (asc.pdf
 
Adt of lists
Adt of listsAdt of lists
Adt of lists
 
How do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdfHow do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdf
 
Homework 05 - Linked Lists (C++)(1) Implement the concepts of a un.pdf
Homework 05 - Linked Lists (C++)(1) Implement the concepts of a un.pdfHomework 05 - Linked Lists (C++)(1) Implement the concepts of a un.pdf
Homework 05 - Linked Lists (C++)(1) Implement the concepts of a un.pdf
 
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdfWrite a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
 
Need Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdf
Need Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdfNeed Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdf
Need Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdf
 
Implement a function called getElements() that takes in two lists. T.pdf
Implement a function called getElements() that takes in two lists. T.pdfImplement a function called getElements() that takes in two lists. T.pdf
Implement a function called getElements() that takes in two lists. T.pdf
 
DS UNIT4_OTHER LIST STRUCTURES.docx
DS UNIT4_OTHER LIST STRUCTURES.docxDS UNIT4_OTHER LIST STRUCTURES.docx
DS UNIT4_OTHER LIST STRUCTURES.docx
 
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
 

More from callawaycorb73779

In a certain Midwest city, a series of studies were conducted to mea.pdf
In a certain Midwest city, a series of studies were conducted to mea.pdfIn a certain Midwest city, a series of studies were conducted to mea.pdf
In a certain Midwest city, a series of studies were conducted to mea.pdfcallawaycorb73779
 
How do conservatives explain economic downturnsSolutionAs the.pdf
How do conservatives explain economic downturnsSolutionAs the.pdfHow do conservatives explain economic downturnsSolutionAs the.pdf
How do conservatives explain economic downturnsSolutionAs the.pdfcallawaycorb73779
 
How would your patient management decisions be influenced by omittin.pdf
How would your patient management decisions be influenced by omittin.pdfHow would your patient management decisions be influenced by omittin.pdf
How would your patient management decisions be influenced by omittin.pdfcallawaycorb73779
 
How is the position of the vascular tissue in roots different from t.pdf
How is the position of the vascular tissue in roots different from t.pdfHow is the position of the vascular tissue in roots different from t.pdf
How is the position of the vascular tissue in roots different from t.pdfcallawaycorb73779
 
Give three examples of how the US finacial Crisis impacted HRM.S.pdf
Give three examples of how the US finacial Crisis impacted HRM.S.pdfGive three examples of how the US finacial Crisis impacted HRM.S.pdf
Give three examples of how the US finacial Crisis impacted HRM.S.pdfcallawaycorb73779
 
Find the object focal point for a combination of two thin lenses who.pdf
Find the object focal point for a combination of two thin lenses who.pdfFind the object focal point for a combination of two thin lenses who.pdf
Find the object focal point for a combination of two thin lenses who.pdfcallawaycorb73779
 
Explain (in points) the roleimportance of the performance of Transp.pdf
Explain (in points) the roleimportance of the performance of Transp.pdfExplain (in points) the roleimportance of the performance of Transp.pdf
Explain (in points) the roleimportance of the performance of Transp.pdfcallawaycorb73779
 
Do students at various colleges differ in how sociable they are 25 .pdf
Do students at various colleges differ in how sociable they are 25 .pdfDo students at various colleges differ in how sociable they are 25 .pdf
Do students at various colleges differ in how sociable they are 25 .pdfcallawaycorb73779
 
describe these organelles and the organisms there found in1. cryst.pdf
describe these organelles and the organisms there found in1. cryst.pdfdescribe these organelles and the organisms there found in1. cryst.pdf
describe these organelles and the organisms there found in1. cryst.pdfcallawaycorb73779
 
Compare the small intestine to the large intestine in terms of histo.pdf
Compare the small intestine to the large intestine in terms of histo.pdfCompare the small intestine to the large intestine in terms of histo.pdf
Compare the small intestine to the large intestine in terms of histo.pdfcallawaycorb73779
 
Chemical composition of rain water.SolutionRainwater gets its .pdf
Chemical composition of rain water.SolutionRainwater gets its .pdfChemical composition of rain water.SolutionRainwater gets its .pdf
Chemical composition of rain water.SolutionRainwater gets its .pdfcallawaycorb73779
 
An adult male receives all his water from a municipal supply that is.pdf
An adult male receives all his water from a municipal supply that is.pdfAn adult male receives all his water from a municipal supply that is.pdf
An adult male receives all his water from a municipal supply that is.pdfcallawaycorb73779
 
1.What does the emergence of autonomous vehicles mean to you What v.pdf
1.What does the emergence of autonomous vehicles mean to you What v.pdf1.What does the emergence of autonomous vehicles mean to you What v.pdf
1.What does the emergence of autonomous vehicles mean to you What v.pdfcallawaycorb73779
 
You have installed a PCIe wireless NIC in a computer desktop in a sm.pdf
You have installed a PCIe wireless NIC in a computer desktop in a sm.pdfYou have installed a PCIe wireless NIC in a computer desktop in a sm.pdf
You have installed a PCIe wireless NIC in a computer desktop in a sm.pdfcallawaycorb73779
 
You have identified a novel enzyme. Supercoiled DNA shows an upward m.pdf
You have identified a novel enzyme. Supercoiled DNA shows an upward m.pdfYou have identified a novel enzyme. Supercoiled DNA shows an upward m.pdf
You have identified a novel enzyme. Supercoiled DNA shows an upward m.pdfcallawaycorb73779
 
Which of the following wireless standards uses direct sequence sprea.pdf
Which of the following wireless standards uses direct sequence sprea.pdfWhich of the following wireless standards uses direct sequence sprea.pdf
Which of the following wireless standards uses direct sequence sprea.pdfcallawaycorb73779
 
Which one of the following statements about lichens is false lichen.pdf
Which one of the following statements about lichens is false  lichen.pdfWhich one of the following statements about lichens is false  lichen.pdf
Which one of the following statements about lichens is false lichen.pdfcallawaycorb73779
 
What is the capability to combine data from separate sources to gain.pdf
What is the capability to combine data from separate sources to gain.pdfWhat is the capability to combine data from separate sources to gain.pdf
What is the capability to combine data from separate sources to gain.pdfcallawaycorb73779
 
What are Factors that influence primary production in different zone.pdf
What are Factors that influence primary production in different zone.pdfWhat are Factors that influence primary production in different zone.pdf
What are Factors that influence primary production in different zone.pdfcallawaycorb73779
 
Using NetBeansQ1. Write a program that uses a stack to convert a n.pdf
Using NetBeansQ1. Write a program that uses a stack to convert a n.pdfUsing NetBeansQ1. Write a program that uses a stack to convert a n.pdf
Using NetBeansQ1. Write a program that uses a stack to convert a n.pdfcallawaycorb73779
 

More from callawaycorb73779 (20)

In a certain Midwest city, a series of studies were conducted to mea.pdf
In a certain Midwest city, a series of studies were conducted to mea.pdfIn a certain Midwest city, a series of studies were conducted to mea.pdf
In a certain Midwest city, a series of studies were conducted to mea.pdf
 
How do conservatives explain economic downturnsSolutionAs the.pdf
How do conservatives explain economic downturnsSolutionAs the.pdfHow do conservatives explain economic downturnsSolutionAs the.pdf
How do conservatives explain economic downturnsSolutionAs the.pdf
 
How would your patient management decisions be influenced by omittin.pdf
How would your patient management decisions be influenced by omittin.pdfHow would your patient management decisions be influenced by omittin.pdf
How would your patient management decisions be influenced by omittin.pdf
 
How is the position of the vascular tissue in roots different from t.pdf
How is the position of the vascular tissue in roots different from t.pdfHow is the position of the vascular tissue in roots different from t.pdf
How is the position of the vascular tissue in roots different from t.pdf
 
Give three examples of how the US finacial Crisis impacted HRM.S.pdf
Give three examples of how the US finacial Crisis impacted HRM.S.pdfGive three examples of how the US finacial Crisis impacted HRM.S.pdf
Give three examples of how the US finacial Crisis impacted HRM.S.pdf
 
Find the object focal point for a combination of two thin lenses who.pdf
Find the object focal point for a combination of two thin lenses who.pdfFind the object focal point for a combination of two thin lenses who.pdf
Find the object focal point for a combination of two thin lenses who.pdf
 
Explain (in points) the roleimportance of the performance of Transp.pdf
Explain (in points) the roleimportance of the performance of Transp.pdfExplain (in points) the roleimportance of the performance of Transp.pdf
Explain (in points) the roleimportance of the performance of Transp.pdf
 
Do students at various colleges differ in how sociable they are 25 .pdf
Do students at various colleges differ in how sociable they are 25 .pdfDo students at various colleges differ in how sociable they are 25 .pdf
Do students at various colleges differ in how sociable they are 25 .pdf
 
describe these organelles and the organisms there found in1. cryst.pdf
describe these organelles and the organisms there found in1. cryst.pdfdescribe these organelles and the organisms there found in1. cryst.pdf
describe these organelles and the organisms there found in1. cryst.pdf
 
Compare the small intestine to the large intestine in terms of histo.pdf
Compare the small intestine to the large intestine in terms of histo.pdfCompare the small intestine to the large intestine in terms of histo.pdf
Compare the small intestine to the large intestine in terms of histo.pdf
 
Chemical composition of rain water.SolutionRainwater gets its .pdf
Chemical composition of rain water.SolutionRainwater gets its .pdfChemical composition of rain water.SolutionRainwater gets its .pdf
Chemical composition of rain water.SolutionRainwater gets its .pdf
 
An adult male receives all his water from a municipal supply that is.pdf
An adult male receives all his water from a municipal supply that is.pdfAn adult male receives all his water from a municipal supply that is.pdf
An adult male receives all his water from a municipal supply that is.pdf
 
1.What does the emergence of autonomous vehicles mean to you What v.pdf
1.What does the emergence of autonomous vehicles mean to you What v.pdf1.What does the emergence of autonomous vehicles mean to you What v.pdf
1.What does the emergence of autonomous vehicles mean to you What v.pdf
 
You have installed a PCIe wireless NIC in a computer desktop in a sm.pdf
You have installed a PCIe wireless NIC in a computer desktop in a sm.pdfYou have installed a PCIe wireless NIC in a computer desktop in a sm.pdf
You have installed a PCIe wireless NIC in a computer desktop in a sm.pdf
 
You have identified a novel enzyme. Supercoiled DNA shows an upward m.pdf
You have identified a novel enzyme. Supercoiled DNA shows an upward m.pdfYou have identified a novel enzyme. Supercoiled DNA shows an upward m.pdf
You have identified a novel enzyme. Supercoiled DNA shows an upward m.pdf
 
Which of the following wireless standards uses direct sequence sprea.pdf
Which of the following wireless standards uses direct sequence sprea.pdfWhich of the following wireless standards uses direct sequence sprea.pdf
Which of the following wireless standards uses direct sequence sprea.pdf
 
Which one of the following statements about lichens is false lichen.pdf
Which one of the following statements about lichens is false  lichen.pdfWhich one of the following statements about lichens is false  lichen.pdf
Which one of the following statements about lichens is false lichen.pdf
 
What is the capability to combine data from separate sources to gain.pdf
What is the capability to combine data from separate sources to gain.pdfWhat is the capability to combine data from separate sources to gain.pdf
What is the capability to combine data from separate sources to gain.pdf
 
What are Factors that influence primary production in different zone.pdf
What are Factors that influence primary production in different zone.pdfWhat are Factors that influence primary production in different zone.pdf
What are Factors that influence primary production in different zone.pdf
 
Using NetBeansQ1. Write a program that uses a stack to convert a n.pdf
Using NetBeansQ1. Write a program that uses a stack to convert a n.pdfUsing NetBeansQ1. Write a program that uses a stack to convert a n.pdf
Using NetBeansQ1. Write a program that uses a stack to convert a n.pdf
 

Recently uploaded

COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsNbelano25
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdfUGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdfNirmal Dwivedi
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfPondicherry University
 
Introduction to TechSoup’s Digital Marketing Services and Use Cases
Introduction to TechSoup’s Digital Marketing  Services and Use CasesIntroduction to TechSoup’s Digital Marketing  Services and Use Cases
Introduction to TechSoup’s Digital Marketing Services and Use CasesTechSoup
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxPooja Bhuva
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonhttgc7rh9c
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Play hard learn harder: The Serious Business of Play
Play hard learn harder:  The Serious Business of PlayPlay hard learn harder:  The Serious Business of Play
Play hard learn harder: The Serious Business of PlayPooky Knightsmith
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
What is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxWhat is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxCeline George
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 

Recently uploaded (20)

VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf arts
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdfUGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
Introduction to TechSoup’s Digital Marketing Services and Use Cases
Introduction to TechSoup’s Digital Marketing  Services and Use CasesIntroduction to TechSoup’s Digital Marketing  Services and Use Cases
Introduction to TechSoup’s Digital Marketing Services and Use Cases
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Play hard learn harder: The Serious Business of Play
Play hard learn harder:  The Serious Business of PlayPlay hard learn harder:  The Serious Business of Play
Play hard learn harder: The Serious Business of Play
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
What is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxWhat is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 

C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf

  • 1. C++ problem Part 1: Recursive Print (40 pts) Please write the recursive List reverse print function, whose iterative version we wrote in class. Below are the function signatures for the functions you are going to need: public: /**Additional Operations*/ void print_reverse(); //Wrapper function that calls the reverse helper function to print a list in reverse //prints nothing if the List is empty private: void reverse(Nodeptr node); //Helper function for the public printReverse() function. //Recursively prints the data in a List in reverse. Why do we need the private helper function here? Since we are going to be reversing our list node by node, in a recursive fashion, we want to pass a one node at a time to our reverse function. However, since our nodes are private, we cannot access them if we call the function inside of main. Add these function signatures to your List.h file along with your other function prototypes inside the class definition. Make sure that you place the reverse function inside the private portion of your List class definition and the print_reverse function prototype to the public portion of your List class definition. Now, implement these two functions inside of List.h, under your section for additional operations. Important: Test each function carefully inside of your ListTest.cpp to make sure that it is working properly. Part 2: Adding an Index to Your List Nodes (20 pts) Next, you will add the following functions to your List.h /**Accessor Functions*/ int get_index(); //Indicates the index of the Node where the iterator is currently pointing //Nodes are numbered from 1 to length of the list //Pre: length != 0
  • 2. //Pre: !off_end() ... int List::get_index() { //Implement the function here } /**Manipulation Procedures*/ void scroll_to_index(int index); //Moves the iterator to the node whose index is specified by the user //Pre: length != 0 ... void scroll_to_index(int index) { //Implement function here } Part 3: Implementing Search as Part of Your List (40 pts) Now, we are going to add two search functions to our List so that we can search for elements in our List. The first of these functions is going to be a simple linear search function. You will need to add the following function prototype and function definition to your List.h: /**Additional Operations*/ int linear_search(listitem item); //Searchs the list, element by element, from the start of the List to the end of the List //Returns the index of the element, if it is found in the List //Returns -1 if the element is not in the List //Pre: length != 0 ... int List::linear_search(listitem item) { //Implement the function here } You are also going to add a function to perform recursive binary search on your List. You will need to add the following function prototype and function definition to your List.h: int binary_search(int low, int high, listitem item); //Recursively searchs the list by dividing the search space in half //Returns the index of the element, if it is found in the List
  • 3. //Returns -1 if the element is not in the List //Pre: length != 0 //Pre: List is sorted (must test on a sorted list) ... int List::binary_search(int low, int high, listitem item) { //Implement the function here } Important: For credit, you must implement the recursive version of binary search. This is my current List.h file: #ifndef LIST_H_ #include //for NULL #include #include #include using namespace std; template class List { private: struct Node { listitem data; Node* next; Node* previous; Node(listitem data) : next(NULL), previous(NULL), data(data) { } }; typedef struct Node* NodePtr; NodePtr start; NodePtr end; NodePtr cursor; int length; void reverse(NodePtr node); //Helper function for the public printReverse() function. //Recursively prints the data in a List in reverse. public:
  • 4. /**Constructors and Destructors*/ List(); //Default constructor; initializes and empty list //Postcondition: list is initialized or is empty ~List(); //Destructor. Frees memory allocated to the list //Postcondition: Memory in the list is deleted List(const List &list); //Copy construcor. Initializes list to have the same elements as another list //Postcondition: Other lists have same elements as the main list /**Accessors*/ listitem get_start(); //Returns the first element in the list //Precondition: first element must not be empty listitem get_end(); //Returns the last element in the list //Precondition: last element must not be empty listitem get_cursor(); //Returns the element pointed to by the iterator //Precondition: the element pointed to by the iterator must not be empty bool is_empty(); //Determines whether a list is empty. bool off_end(); //Determines if the iterator is off the end of the list (i.e. whether cursor is NULL) int get_length(); //Returns the length of the list /**Manipulation Procedures*/ void begin_cursor(); //Moves the iterator to point to the first element in the list //If the list is empty, the iterator remains NULL //Postcondition: the iterator point to the first element in the list void add_cursor(listitem data); //Inserts a new element into the list in the position after the iterator //Precondition: the iterator must point to an element //Postcondition: a new element is inserted in the position after the iterator void remove_end();
  • 5. //Removes the value of the last element in the list //Precondition: last element is not a null object //Postcondition: the the value of the last element in the list is removed void remove_start(); //Removes the value of the first element in the list //Precondition: first element is not a null object //Postcondition: the value of the first element in the list is removed void add_end(listitem data); //Inserts a new element at the end of the list //If the list is empty, the new element becomes both start and end //Postcondition: a new element is inserted at the end of the list void add_start(listitem data); //Inserts a new element at the start of the list //If the list is empty, the new element becomes both start and end //Postcondition: a new element is inserted at the start of the list void remove_cursor(); //Removes the element pointed at by the iterator //Precondition: the element pointed at by the iterator is not a null object //Postcondition: the element pointed at by the iterator is removed void move_cursor(); //Moves the iterator forward by one element in the list //Precondition: the next element is not a null object //Postcondition: the iterator moves forward by one element in the list /**Additional List Operations*/ void print(); //Prints to the console the value of each element in the list sequentially //and separated by a blank space //Prints nothing if the list is empty bool operator==(const List &list); //Tests two lists to determine whether their contents are equal //Postcondition: returns true if lists are equal and false otherwise /**Additional Operations*/ void print_reverse(); //Wrapper function that calls the reverse helper function to print a list in reverse //prints nothing if the List is empty };
  • 6. template List::List() : start(NULL), end(NULL), cursor(NULL), length(0) { } template List::~List() { cursor = start; NodePtr temp; while (cursor != NULL) { temp = cursor->next; delete cursor; cursor = temp; } } template List::List(const List &list) : length(list.length) { if (list.start == NULL) //If the original list is empty, make an empty list for this list { start = end = cursor = NULL; } else { start = new Node(list.start->data); //using second Node constructor NodePtr temp = list.start; //set a temporary node pointer to point at the start of the original list cursor = start; //set iterator to point to start of the new list while (temp->next != NULL) { temp = temp->next; //advance up to the next node in the original list cursor->next = new Node(temp->data); //using node constructor to create a new node with copy of data cursor = cursor->next; //advance to this new node } end = cursor; //Why do I need this line of code? cursor = NULL; } } template
  • 7. void List::print() { NodePtr temp = start; //create a temporary iterator while (temp != NULL) { //What two lines of code go here? cout << temp->data << " "; temp = temp->next; //Hint: One statement should contain a cout } cout << endl; //What does this do? } template void List::add_start(listitem data) { if (length == 0) //Why is this necessary? { start = new Node(data); end = start; } else { NodePtr N = new Node(data); //create the new node by calling the node constructor N->next = start; //set the new node's next field to point to the start start->previous = N; start = N; //make the start be the new node } length++; } template void List::add_end(listitem data) { if (length == 0) { start = new Node(data); end = start; } else { NodePtr N = new Node(data); //create the new node by calling the node constructor end->next = N; N->previous = end; end = N; } length++;
  • 8. } template bool List::is_empty() { return (length == 0); } template int List::get_length() { return length; } template listitem List::get_start() { assert(start != NULL); return start->data; } template listitem List::get_end() { assert(end != NULL); return end->data; } template void List::begin_cursor() { cursor = start; } template listitem List::get_cursor() { assert(cursor != NULL); return cursor->data; } template void List::move_cursor() { assert(cursor != NULL); cursor = cursor->next; } template bool List::off_end() { return (cursor == NULL);
  • 9. } template void List::remove_start() { assert(length != 0); if (length == 1) { delete start; start = end = cursor = NULL; length = 0; } else { if (cursor == start) cursor = NULL; start = start->next; delete start->previous; start->previous = NULL; length--; } } template void List::remove_end() { assert(length != 0); if (length == 1) { delete end; start = end = cursor = NULL; length = 0; } else { if (cursor == end) cursor = NULL; end = end->previous; delete end->next; end->next = NULL; length--; } } template void List::add_cursor(listitem data) { assert(!off_end());
  • 10. if (cursor == end) { add_end(data); } else { NodePtr newNode = new Node(data); newNode->next = cursor->next; newNode->previous = cursor; cursor->next->previous = newNode; cursor->next = newNode; length++; } } template void List::remove_cursor() { assert(cursor != NULL); if (cursor == start) { remove_start(); } else if (cursor == end) { remove_end(); } else { cursor->previous->next = cursor->next; cursor->next->previous = cursor->previous; delete cursor; cursor = NULL; length--; } } template bool List::operator==(const List& list) { if (length != list.length) return false; NodePtr temp1 = start; NodePtr temp2 = list.start; while (temp1 != NULL) { if (temp1->data != temp2->data) return false; temp1 = temp1->next;
  • 11. temp2 = temp2->next; } return true; } #define LIST_H_ #endif /* LIST_H_ */ Solution Lisht.h #include "stdafx.h" #include #include using namespace std; template class List { private: struct Node { listitem data; Node* next; Node* previous; Node(listitem data) : next(NULL), previous(NULL), data(data) { } }; typedef struct Node* NodePtr; NodePtr start; NodePtr end; NodePtr cursor; int length; void reverse(NodePtr node); public: List(); ~List(); List(const List &list);
  • 12. listitem get_start(); listitem get_end(); listitem get_cursor(); bool is_empty(); bool off_end(); int get_length(); void begin_cursor(); void add_cursor(listitem data); void remove_end(); void remove_start(); void add_end(listitem data); void add_start(listitem data); void remove_cursor(); void move_cursor(); void print(); bool operator==(const List &list); // Answer void print_reverse(); int get_index(); void scroll_to_index(int index); int linear_search(listitem item); int binary_search(int low, int high, listitem item); void sort(NodePtr small); }; List.cpp #include "stdafx.h" #include"List.h" template List::List() : start(NULL), end(NULL), cursor(NULL), length(0) { } template List::~List() { cursor = start;
  • 13. NodePtr temp; while (cursor != NULL) { temp = cursor->next; delete cursor; cursor = temp; } } template List::List(const List &list) : length(list.length) { if (list.start == NULL) //If the original list is empty, make an empty list for this list { start = end = cursor = NULL; } else { start = new Node(list.start->data); //using second Node constructor NodePtr temp = list.start; //set a temporary node pointer to point at the start of the original list cursor = start; //set iterator to point to start of the new list while (temp->next != NULL) { temp = temp->next; //advance up to the next node in the original list cursor->next = new Node(temp->data); //using node constructor to create a new node with copy of data cursor = cursor->next; //advance to this new node } end = cursor; //Why do I need this line of code? cursor = NULL; } } template void List::print() { NodePtr temp = start; //create a temporary iterator while (temp != NULL) { //What two lines of code go here? cout << temp->data << " "; temp = temp->next; //Hint: One statement should contain a cout
  • 14. } cout << endl; //What does this do? } template void List::add_start(listitem data) { if (length == 0) //Why is this necessary? { start = new Node(data); end = start; } else { NodePtr N = new Node(data); //create the new node by calling the node constructor N->next = start; //set the new node's next field to point to the start start->previous = N; start = N; //make the start be the new node } length++; } template void List::add_end(listitem data) { if (length == 0) { start = new Node(data); end = start; } else { NodePtr N = new Node(data); //create the new node by calling the node constructor end->next = N; N->previous = end; end = N; } length++; } template bool List::is_empty() { return (length == 0); }
  • 15. template int List::get_length() { return length; } template listitem List::get_start() { assert(start != NULL); return start->data; } template listitem List::get_end() { assert(end != NULL); return end->data; } template void List::begin_cursor() { cursor = start; } template listitem List::get_cursor() { assert(cursor != NULL); return cursor->data; } template void List::move_cursor() { assert(cursor != NULL); cursor = cursor->next; } template bool List::off_end() { return (cursor == NULL); } template void List::remove_start() { assert(length != 0); if (length == 1) {
  • 16. delete start; start = end = cursor = NULL; length = 0; } else { if (cursor == start) cursor = NULL; start = start->next; delete start->previous; start->previous = NULL; length--; } } template void List::remove_end() { assert(length != 0); if (length == 1) { delete end; start = end = cursor = NULL; length = 0; } else { if (cursor == end) cursor = NULL; end = end->previous; delete end->next; end->next = NULL; length--; } } template void List::add_cursor(listitem data) { assert(!off_end()); if (cursor == end) { add_end(data); }
  • 17. else { NodePtr newNode = new Node(data); newNode->next = cursor->next; newNode->previous = cursor; cursor->next->previous = newNode; cursor->next = newNode; length++; } } template void List::remove_cursor() { assert(cursor != NULL); if (cursor == start) { remove_start(); } else if (cursor == end) { remove_end(); } else { cursor->previous->next = cursor->next; cursor->next->previous = cursor->previous; delete cursor; cursor = NULL; length--; } } template bool List::operator==(const List& list) { if (length != list.length) return false; NodePtr temp1 = start; NodePtr temp2 = list.start; while (temp1 != NULL) { if (temp1->data != temp2->data) return false; temp1 = temp1->next;
  • 18. temp2 = temp2->next; } return true; } template void List::reverse(NodePtr list) { if (list) { reverse(list->next); cout << list->data << endl; } } template void List::print_reverse() { reverse(start); } template int List::get_index() { if (off_end() == true) { cout << "Error! Iterator is not pointing to anything..." << endl; return 0; } else { int count = 1; NodePtr temp = start; while (temp != cursor) { count++; temp = temp->next; } return count; }
  • 19. } template void List::scroll_to_index(int index) { int max = get_length(); for (int j = index; j <= max; j++) { get_cursor(j); if (cursor == NULL) cout << "Calling scroll when iterator is NULL" << endl; else cursor = cursor->next; } } template int List::linear_search(listitem item) { NodePtr temp = start; int count = 1; bool valFound = false; while (temp != NULL) { if (temp->data == item) { valFound = true; temp = NULL; } else { count++; temp = temp->next; } } if (valFound == false) { cout << "Error. Item not found" << endl;