public ListItem getnth (int n) { if (getNumItems () == 0) { return null; } else { for (int i = 1 ; i == n ;) { Current = Head; Current = Current.getNext (); i++; } return Current; } } } I wrote this method to get nth item in queue but its not working properly
Move Current = Head outside of the loop
it's outside
oh wait lol yh i was checking to see if tht was the problem but it still isnt working
would u like me to send u the whole code?
thts the listitem class file
thats the queue file
thts the test class file
if u have a ready compiler u can run it
What's not working?
the base file
i think thts all the files might have pasted one twice not sure
Describe what you're trying to do, what you expect to happen, and what actually happens.
im trying to access nth item in a list
shouldn't for "(int i = 1 ; i == n ;)" be "for (int i = 1 ; i <= n ;)" ?
lemme try tht, crap, wait how do exit conditions work in java, still trying to learn language
Good catch, across
lol thnkx
so for loops the thing will iterate until out of bounds
lol fail error thnkx guys
That's correct. for(int i = 0; i < 10; i++); That loop will iterate 10 times before terminating. And you're welcome.
Join our real-time social learning platform and learn together with your friends!