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

Click For Summary
The error "The operator > is undefined for the argument type(s) E, E" occurs because Java generics do not support direct comparison using operators like >. To compare generic values, a comparator must be used, typically by implementing the Comparable interface or using a Comparator class. The discussion highlights the need for a proper comparison method for generic types, referencing the Collections.sort method as a standard approach. The user is seeking guidance on how to implement this correctly in their heap addition method. Understanding how to work with generics and comparisons is essential for resolving this issue.
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.
 
Greetings to all, I am writing with a question regarding graph generation in LTSpice. I am using LTSpice XVII and am trying to plot AM-AM and AM-PM characterization for a power amplifier, but I haven't been successful yet, likely due to my lack of practice with this specific analysis. I have been using a square wave input at 8.2 MHz as the voltage waveform for my power amplifier. It is said that for a switching amplifier like Class-D, the AM-AM / AM-PM (amplitude-to-amplitude and...
Thread 'How do I determine the resistance for RLC low pass filter?'
Hi, I am trying to build a RLC low pass filter that atenuates the frequency below 4500 Hz. However, I have encountered some problem when choosing the correct R to work with. Here is the Circuit Here is the original sound. Here is my code in Matlab function Vout = myFilterCircuit(Vin,h) n_V = length(Vin); f_7 = 4470;; % Undesired frequency h_7 = h; % delta time % These are for the constant and initialization of the variables t_7 = 0:h_7:(n_V-1)*h_7; % This is the independent variable...

Similar threads

Replies
1
Views
11K
Replies
12
Views
2K
Replies
2
Views
4K
Replies
5
Views
3K
Replies
2
Views
3K
Replies
3
Views
2K
Replies
1
Views
1K
Replies
1
Views
9K