Question

Complete the defintion of operator() for the function object Comp that properly compares two int values...

Complete the defintion of operator() for the function object Comp that properly compares two int values to the following priority in C++:

-Even is higher priority than odd and

-larger numbers have higher priority than smaller numbers.

struct Comp {
    bool operator()(const int& lhs,const int& rhs) const {
        
        return false;
    }
};
0 0
Add a comment Improve this question Transcribed image text
Answer #1
struct Comp {
    bool operator()(const int& lhs,const int& rhs) const {
        if (lhs % 2 == 0 && rhs % 2 == 0) {
            return lhs > rhs;
        }
        return lhs % 2 == 0;
    }
};
Add a comment
Know the answer?
Add Answer to:
Complete the defintion of operator() for the function object Comp that properly compares two int values...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • HELP PLEASE ANSWER 3(c). Consider the following function object: #include <string> class CustomCompare public: bool operator...

    HELP PLEASE ANSWER 3(c). Consider the following function object: #include <string> class CustomCompare public: bool operator (const atd:istringk 1hs, const std::string& rhs) if (1hs. length) 0 && rhs.lengthO 0) return false; int 1 lhs. length )-1; intr rhs. length)-1; return (ro&&10) I Write one C++ statement that defines a variable myCustomPQ, where myCustomPQ is a priority queue storing strings and using CustomCompare.

  • C++ When running my tests for my char constructor the assertion is coming back false and...

    C++ When running my tests for my char constructor the assertion is coming back false and when printing the string garbage is printing that is different everytime but i dont know where it is wrong Requirements: You CANNOT use the C++ standard string or any other libraries for this assignment, except where specified. You must use your ADT string for the later parts of the assignment. using namespace std; is stricly forbiden. As are any global using statements. Name the...

  • Language: C++ Complete this function 1.Object &raw_front() { // Return the element at the front of...

    Language: C++ Complete this function 1.Object &raw_front() { // Return the element at the front of the list *without* using the iterator classes // (You may assume the list is not empty) // Place your code here. Code: #ifndef LIST_H #define LIST_H #include using namespace std; template class List { private: // The basic doubly linked list node. // Nested inside of List, can be public // because the Node is itself private struct Node { Object data; Node *prev;...

  • My question is pretty simple, I just want to know how to call my operator== function...

    My question is pretty simple, I just want to know how to call my operator== function in Stack.cpp using a list function. Here is what I meant. This is my Stack.h file: class Stack { public:    /**constructors and destructors*/    Stack();    Stack(const Stack &S);    ~Stack();    void pop();    void push(int data);    bool operator==(const Stack &S); [ .......] private:    List<int> stack; }; Here is my List.h file: template<class listitem> class List { private:    struct...

  • Code in c++ please. Does not have to be complete, just write code for the ones you know. Thank y...

    Code in c++ please. Does not have to be complete, just write code for the ones you know. Thank you. template <typename T> class smart_ptr { public: smart_ptr(); // Create a smart_ptr that is initialized to nullptr. The reference count // should be initialized to nullptr. explicit smart_ptr(T* raw_ptr); // Create a smart_ptr that is initialized to raw_ptr. The reference count // should be one. smart_ptr(const smart_ptr& rhs); // Copy construct a pointer from rhs. The reference count should be...

  • void card:: setNum(int n) { assert(n >= 1 && n <= 13); num = n; }...

    void card:: setNum(int n) { assert(n >= 1 && n <= 13); num = n; } void card::setSuit(char s) { assert(s == 'C' || s == 'D' || s == 'H' || s == 'S'); suit = s; } int card::getNum() { assert(num >= 1 && num <= 13); return num; } char card::getSuit() { assert(suit == 'C' || suit == 'D' || suit == 'H' || suit == 'S'); return suit; } string card:: read() { string output=""; if...

  • C++ LinkedList I need the code for copy constructor and assignment operator #include <iostream> #include <string> using namespace std; typedef string ItemType; struct Node {    ItemType va...

    C++ LinkedList I need the code for copy constructor and assignment operator #include <iostream> #include <string> using namespace std; typedef string ItemType; struct Node {    ItemType value;    Node *next; }; class LinkedList { private:    Node *head;    // You may add whatever private data members or private member functions you want to this class.    void printReverseRecursiveHelper(Node *temp) const; public:    // default constructor    LinkedList() : head(nullptr) { }    // copy constructor    LinkedList(const LinkedList& rhs);    // Destroys all the dynamically allocated memory    //...

  • 1. void raw_push_front(const Object &x) { // insert x at the head of the list *without*...

    1. void raw_push_front(const Object &x) { // insert x at the head of the list *without* using the iterator classes // Place your code here. } 2. void raw_push_back(const Object &x) { // insert x at the tail of the list *without* using the iterator classes // Place your code here. } #ifndef LIST_H #define LIST_H #include <algorithm> using namespace std; template<typename Object> class List { private: // The basic doubly linked list node. // Nested inside of List, can...

  • I have the following c++ data structures assignment: Copy Constructors, Destructors, and Assignment Operators An understanding...

    I have the following c++ data structures assignment: Copy Constructors, Destructors, and Assignment Operators An understanding of how to implement copy constructors, destructors, and assignment operators is essential when working with data structures using dynamic memory allocation. Failure to implement these methods correctly can and probably will result in memory leaks. In this project, you are provided with a working implementation of a doubly-linked list in which the copy constructor, destructor, and assignment operator methods are not complete. To complete...

  • //codes in DynamicString.cpp #include "DynamicString.h" int DynamicString::myStringLen(const char* str){ //TODO::Implement me return -1; } DynamicString::DynamicString(){ //TODO::1::Implement...

    //codes in DynamicString.cpp #include "DynamicString.h" int DynamicString::myStringLen(const char* str){ //TODO::Implement me return -1; } DynamicString::DynamicString(){ //TODO::1::Implement me } DynamicString::DynamicString(const char* str){ //TODO::1::Implement me } int DynamicString::len() const{ //TODO::1::Implement me return -1; } const char* DynamicString::c_str() const{ //TODO::1::Implement me return nullptr; } char& DynamicString::char_at(int position){ //TODO::1::Implement me char* a = new char('a'); return *a; } char DynamicString::char_at(int position) const{ //TODO::1::Implement me return 'a'; } char& DynamicString::operator[](int position){ //TODO::1::Implement me char* a = new char('a'); return *a; } char DynamicString::operator[](int position) const{...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT