Question

Add a recursive Boolean function called bool isGreater(int compare) to class IntegerLinkedList to check if any...

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);
}
  
};

Homework Answers

Answer #1

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);
}
  
};

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
c++ data structures linked list delete node bool deleteNode(int); pass this method an id to delete....
c++ data structures linked list delete node bool deleteNode(int); pass this method an id to delete. Return true or false to indicate success or failure. Delete the memory the node was using The algorithm for deleting a Node to a Linked List (general case): ● Begin at the head. ● Compare the id to the current node. ● If search id > current id, stop. ● Detach the current Node ○ current->previous->next = current->next ○ current->next->previous = current->previous ● Deallocate...
IntNode class I am providing the IntNode class you are required to use. Place this class...
IntNode class I am providing the IntNode class you are required to use. Place this class definition within the IntList.h file exactly as is. Make sure you place it above the definition of your IntList class. Notice that you will not code an implementation file for the IntNode class. The IntNode constructor has been defined inline (within the class declaration). Do not write any other functions for the IntNode class. Use as is. struct IntNode { int data; IntNode *next;...
Using the following definition for a BST node: class BTNode { public: int data; BTNode *left;...
Using the following definition for a BST node: class BTNode { public: int data; BTNode *left; BTNode *right; BTNode(int d,BTNode *l=nullptr,BTNode *r=nullptr) :data(d),left(l),right(r) {} }; Implement a function to calculate the balance factor of a node in a BST. The function prototype must match the following function: int balance_factor(BTNode *subtree) { // IMPLEMENT return -2; } You may implement other functions to help you. In particular, you may want to implement a function to calculate a node's height. //C++ #include...
Data Structures using C++ Searching a Linked List Here are the declarations for a simple unsorted...
Data Structures using C++ Searching a Linked List Here are the declarations for a simple unsorted linked list of ints that ends in a null pointer. //=============================================================== class Cell { friend class UList; private: int data; Cell* next; Cell( int dt, Cell* nx=nullptr ) : data(dt), next(nx) {} }; //=============================================================== class UList { private: Cell* head = nullptr;    // stationary head pointer. Cell* scan = nullptr;          // for walking down the List. Cell* follow = nullptr; public: void find( int...
Implement the getNodeAtPosition function of the LinkedList class . Node * LinkedList::getNodeAtPosition(int position) The job of...
Implement the getNodeAtPosition function of the LinkedList class . Node * LinkedList::getNodeAtPosition(int position) The job of this function is to return a pointer to the node the node at the given position. If the list is empty, position <= 0 or position > length, then the function should return the null pointer. This is a helper function that can be used by various other member functions (e.g. insertAtPosition, removeAtPosition, getValue. setValue). I started with this: LinkedList::LinkedList(int myArray[], int size) {...
The class CourseList implements a simple database of students registered in a course. Complete the method...
The class CourseList implements a simple database of students registered in a course. Complete the method countAttendees in the code below such that it returns the number of students in the instance of CourseList who have not attended any classes. Your response may be written in Java or pseudocode. Your code cannot modify the linked list. The class Node is similar to the linked list node object discussed in lecture. You can use helper methods, but this is not necessary....
Given the following specifications for an array-based unsorted list, implement all of the functions (declared below)...
Given the following specifications for an array-based unsorted list, implement all of the functions (declared below) and a write a driver code to test all of your implementations. // Define a structure to use as the list item struct ListItem { int key; int Data; }; #define MAX_SIZE 50 // Define maximum length of the list class UnsortedArray { private: int head; // Index to head of the list ListItem theList[MAX_SIZE]; // The list public: UnsortedArray(); // Class constructor ~...
The following program creates a linked list which contains 5 links. Add a method called doubleValue()...
The following program creates a linked list which contains 5 links. Add a method called doubleValue() to the LinkedList class. The doubleValue() method must double the value of the number data field in each link. Add the required code to the main() method to call the doubleValue() method and display the revised list. public class Link { private int number; private Link next;      public Link(int x) { number = x; }    public void displayLink() { System.out.println("The number is:...
The following program creates a linked list which contains 5 links. Add a method called doubleValue()...
The following program creates a linked list which contains 5 links. Add a method called doubleValue() to the LinkedList class. The doubleValue() method must double the value of the number data field in each link. Add the required code to the main() method to call the doubleValue() method and display the revised list. public class Link { private int number; private Link next;      public Link(int x) { number = x; }    public void displayLink() { System.out.println("The number is:...
Data Structure in C++ I keep getting the same warning, and I cant seem to fix...
Data Structure in C++ I keep getting the same warning, and I cant seem to fix it.. Can you explain to me what I am doing wrong? Warning: dlist.cc: In function 'std::ostream& operator<<(std::ostream&, dlist&)': dlist.cc:66:10: error: invalid initialization of reference of type 'std::ostream& {aka std::basic_ostream&}' from expression of type 'dlist::node*' dlist.cc: In function 'dlist operator+(dlist&, dlist&)': dlist.cc:93:8: error: invalid operands of types 'dlist::node*' and 'dlist::node*' to binary 'operator+' dlist.cc:97:8: error: could not convert 'result' from 'int' to 'dlist' My code:...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT
Active Questions
  • For an OR gate, which of the following input combinations produces a LOGIC Low output? x...
    asked 3 minutes ago
  • The Pentium 4 Prescott processor, released in 2004, had a clock rate of 3.6 GHz and...
    asked 14 minutes ago
  • Which of the following selectors matches an h1 heading with the id “topHeading”? h1#topHeading h1[id=“topHeading”] h1...
    asked 16 minutes ago
  • Assume a Poisson distribution. a. If lambda=2.5​, find ​P(X=5​). b. If lambda=8.0​, find ​P(X=10​). c. If...
    asked 26 minutes ago
  • 4) Course: Programming Fundamentals III Textbook: A Practical Introduction to Data Structures and Algorithm Analysis Edition...
    asked 32 minutes ago
  • Explain how the proportions for two populations are used in hypotheses testing about two population proportions.
    asked 48 minutes ago
  • Suppose as a researcher you gather green turtles from a beach where the magnetic field strength...
    asked 55 minutes ago
  • AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA choose two dif
    asked 1 hour ago
  • Can someone please explain this to me? Suppose that the Go-Back-N protocol with ? = 3...
    asked 1 hour ago
  • The daily sales of gasoline (in liters) at a service stations are assumed to be uniformly...
    asked 1 hour ago
  • Add a recursive Boolean function called bool isGreater(int compare) to class IntegerLinkedList to check if any...
    asked 1 hour ago
  • 1. Explain how performance of a database system is measured. Additionally, differentiate between response time and...
    asked 1 hour ago