Question

I am getting an "invalid operands to binary" error for the lines "pp->element == value" and...

I am getting an "invalid operands to binary" error for the lines "pp->element == value" and "pp->left->element > value".

int insert(NodeT **pp, Element value)
{

    if (pp->element == value)
    {
        return 0;
    }

    else if (pp->left->element > value)
    {
        pp->left = allocateNode(value);
    }
    
    else
    {
        pp->right = allocateNode(value);
    }
}

Homework Answers

Answer #1

According to my knowledge,as the code is not completely given,I can say that either of the reasons:

1.)

When comparing two values, they must be of the same type. This is because pointer arithmetic in C is based on the size of the pointers, so for example if you subtract char* from int* you have a 1-byte object and a 4-byte object, and so there is no way for the compiler to know whether the result should be in 1-byte units or 4-byte units.

I realize your two values are both single bytes, but it's still not allowed in standard C (which makes no assumptions that objects of different types would be stored in the same area, etc.).

2.)In pp->element the "element" would not be of type Nodet or else it is not a pointer.

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
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:...
Question: I get a Segmentation fault error sometimes when I addElementBack or print. Am I using...
Question: I get a Segmentation fault error sometimes when I addElementBack or print. Am I using pointers correctly and deleting memory properly? #ifndef DYNAMICARRAY_H #define DYNAMICARRAY_H #include <cstdlib> #include <iostream> using namespace std; // Node class class Node { int data; Node* next; Node* prev; public: Node(); Node(int); void SetData(int newData) { data = newData; }; void SetNext(Node* newNext) { next = newNext; }; void SetPrev(Node* newPrev) { prev = newPrev; }; int getData() { return data; }; Node* getNext()...
Here is my java code, I keep getting this error and I do not know how...
Here is my java code, I keep getting this error and I do not know how to fix it: PigLatin.java:3: error: class Main is public, should be declared in a file named Main.java public class Main { ^ import java.io.*; public class Main { private static BufferedReader buf = new BufferedReader( new InputStreamReader(System.in)); public static void main(String[] args) throws IOException { String english = getString(); String translated = translate(english); System.out.println(translated); } private static String translate(String s) { String latin =...
For some reason I followed the steps in my project and I am getting the incorrect...
For some reason I followed the steps in my project and I am getting the incorrect output and when I am submitting it, it gives me compilation error. Printing empty array -- next line should be blank Testing append: Shouldn't crash! Should print 100 through 110 below, with 110 on a new line: 100 101 102 103 104 105 106 107 108 109 110 Checking capacity of new array: OK Append test #2: Should print 100 through 120 below, on...
why am I getting this error with this code? :print('Women: {:.2f} calories'.format('calories_woman')) THIS IS THE ERROR...
why am I getting this error with this code? :print('Women: {:.2f} calories'.format('calories_woman')) THIS IS THE ERROR I AM GETTING :ValueError: Unknown format code 'f' for object of type 'str'
This is an example out of my text which I copied directly but am getting an...
This is an example out of my text which I copied directly but am getting an error every iteration and am unsure how to correct it. The error is " the condition has length > 1 and only the first element will be used" and my code is: f <- function(x, sigma) { if (any(x < 0)) return(0) stopifnot(sigma > 0) return((x/sigma^2)*exp(-x^2 / (s*sigma^2))) } xt <- x[i-1] y <- rchisq(1, df = xt) m <- 10000 sigma <- 4...
In this lab, you will write a program that creates a binary search tree based on...
In this lab, you will write a program that creates a binary search tree based on user input. Then, the user will indicate what order to print the values in. **Please write in C code** Start with the bst.h and bst.c base code provided to you. You will need to modify the source and header file to complete this lab. bst.h: #ifndef BST_H #define BST_H typedef struct BSTNode { int value; struct BSTNode* left; struct BSTNode* right; } BSTNode; BSTNode*...
Run the below code and shift binary left and right and understand the output. #include <stdio.h>...
Run the below code and shift binary left and right and understand the output. #include <stdio.h> int main() {     int num=212, i;     for (i=0; i<=2; i++)         printf("Right shift by %d: %d\n", i, num>>i);      printf("\n");      for (i=0; i<=2; i++)         printf("Left shift by %d: %d\n", i, num<<i);             return 0; } Output:
How do I fix my error of binding on line 74? #include <iostream> #include <fstream> #include...
How do I fix my error of binding on line 74? #include <iostream> #include <fstream> #include <cctype> #include <cstring> #include <iomanip> using namespace std; #include "AvlTree.h" class WordCount { public:     char *word;     int *lines;     int count;     int size;     bool operator<(const WordCount &rhs) const {return strcmp(word, rhs.word) < 0;}     bool operator!= (const WordCount &rhs) const {return strcmp(word, rhs.word) != 0;}     WordCount():lines(NULL), count(0), size(0) {word = new char[1]; word[0] = '\0';}     friend ostream& operator<<...
Getting the following errors: Error 1 error C2436: '{ctor}' : member function or nested class in...
Getting the following errors: Error 1 error C2436: '{ctor}' : member function or nested class in constructor initializer list on line 565 Error 2 error C2436: '{ctor}' : member function or nested class in constructor initializer list on line 761 I need this code to COMPILE and RUN, but I cannot get rid of this error. Please Help!! #include #include #include #include using namespace std; enum contactGroupType {// used in extPersonType FAMILY, FRIEND, BUSINESS, UNFILLED }; class addressType { private:...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT