1. PF Contest - Win "Conquering the Physics GRE" book! Click Here to Enter
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Java Error: The operator > is undefined for the argument type(s) E, E

  1. Dec 6, 2011 #1
    1. The problem statement, all variables and given/known data

    2. Relevant equations

    3. The attempt at a solution

    Hello. The method here is to add an item to a heap. As the title states, I am getting the error "The operator > is undefined for the argument type(s) E, E" in the parenthesis after the while. I assume this is not the correct way to compare E values. Does anybody know what would be the correct way?

    Code (Text):

        public boolean add(E item) {
            data[size] = item;
            child = size - 1;
            parent = (child-1) / 2;
            while (parent >= 0 && data[parent] > data[child]) {
                // swap data[parent] and data[child]
                child = parent;
                parent = (child - 1) / 2;
  2. jcsd
  3. Dec 6, 2011 #2
    Anyone? data[] is an array that holds generics. I should have said that instead of saying "E." I can't seem to find a decent website that explains how to compare generic values.
  4. Dec 6, 2011 #3


    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook