while loop (so that while the current element in the list is less than the parameter, go to the next element)….but how do I do this? I can’t do < or compareTo, so I’m not sure how to do this.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
add(..)method semantics is usually to add to the end of the list. So you can simply hold a reference to thetailnode (in addition tohead), and insert after it. Apart from that, addition at a specified position is O(n) for a linked-list – you have to loop through the elements one by one until you reach the target index.