And that small fix is changing the person Class?
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
And that small fix is changing the person Class?
No the code using the compareTo method. It needs to have a reference to the name in the Person in the Node and a reference to the name in the Person from the user.
If you don't understand my answer, don't ignore it, ask a question.
Okay, so inside the method insert I need to have those references?
--- Update ---
Okay I've figured it out
class PhoneBookList implements PhoneBook { private int size = 0; Node head = null; private static final class Node { final Person person; Node next; Node(Person person) { this.person = person; } } public boolean insert(Person person) { Node n = new Node(person); Node p = head; if(p == null) { head = n; size++; return true; } else { Node temp = p; int comparison; while(temp.next != null) { comparison = temp.person.name.compareTo(person.name); if(comparison == 0){ return false; } temp = temp.next; } temp.next = n; size++; return true; } } }
I'll go on to implement the other methods as well. Thank you for your help, you can count on me me coming back hahha
I am Glad to hear you figured it out. I'll see you later for your next problem.
If you don't understand my answer, don't ignore it, ask a question.
arhzz (May 16th, 2020)