Add a recursive Boolean function called bool isGreater(int compare) to class IntegerLinkedList to check if any of the linked list data values is greater than the given parameter, compare.
For example, isGreater(25) should return true and isGreater(100) should return false for the the linked list shown below. A main function (prob3.cpp) is given to you to add data values to the linked list and test your function. Other examples are given in the main function.
// ADD ANSWER TO THIS FILE
#pragma once
class SNode {
public:
int data;
SNode *next;
};
class IntegerLinkedList {
private:
SNode *head;
bool isGreater (SNode *ptr, int compare) {
return false; // COMPLETE THIS FOR PROBLEM 3
}
public:
IntegerLinkedList() {
head = nullptr;
}
void addFront(int x) {
SNode *tmp = head;
head = new SNode;
head->next = tmp;
head->data = x;
}
int getIndexLargest(); // COMPLETE THIS FOR PROBLEM 2
// recursion helper function called from main
bool isGreaterHelper (int compare) {
return isGreater(head, compare);
}
};
class SNode {
public:
int data;
SNode *next;
};
class IntegerLinkedList {
private:
SNode *head;
bool isGreater (SNode *ptr, int compare) {
if(ptr!=NULL)//runs until end of the list is reached
return false; // COMPLETE THIS FOR PROBLEM 3
if(ptr->data > compare)return true;//if
found
return isGreater(ptr->next,compare);
}
public:
IntegerLinkedList() {
head = nullptr;
}
void addFront(int x) {
SNode *tmp = head;
head = new SNode;
head->next = tmp;
head->data = x;
}
int getIndexLargest(); // COMPLETE THIS FOR PROBLEM 2
// recursion helper function called from main
bool isGreaterHelper (int compare) {
return isGreater(head, compare);
}
};
Get Answers For Free
Most questions answered within 1 hours.