First of all, I'd like to thank you for that time when you helped you, I really appreciate this.
So I hope again for some help from you if you can please ...
I am doing LinkedStack and almost methods are working, I've tested in JUnit, and they are working
but the IndexOf method is not working, and I googled for a solution and nothing, so you'll see below my variant how I've tried and hope you can help me with this .
Thanks in advance ;)
I've tried but it gives syntax error
We have this method:
I assume that T is a generic type.
Then we have:
So, top.getElement can be cast to an int, but I can't place that with the line following, where element of type T is tested for equality against something that can be cast to an int.
Is T a bound generic type? If so, what is the bound?
And what is top?
Carey Brown wrote:LinearNode node = top;
for( i=0 ; i < count && ! ((element == null && node.element == null) || node.element.equals(element)) ; i++, node = node.getNext() )
if( i == count )
Edit: Note that this method only works if T has a usefull equals method.
Congratulations. I'm glad this worked for you. If you really do have data with null in it you'll need to incorporate Paul's suggestion.
Constantin Cornea wrote:Finally, the only change that I did is just node.getElement() as you can see below :
A minor note: Having a trailing semi colon at the end of a for() loop is often a bug. In this case it is not and to emphasize this I put it on its own line below the for() to show that it's an empty statement. You could do the same thing (perhaps better) with an empty set of braces.