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

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
2 replies · 10K views
trouty323
Messages
23
Reaction score
0


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:
	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;
		}
	}
 
Physics news on Phys.org
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.