Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void addContact(String name, String phone) {
- Node<Contact> pos = lst;
- while(pos != null && name.equals(pos.getInfo().getName())){
- pos = pos.getNext();
- }
- if (pos != null){
- pos.getInfo().setPhone(phone);
- }else{
- pos = lst;
- Node<Contact> prev = null;
- while(pos != null && name.compareTo(pos.getInfo().getName())>0){
- prev = pos;
- pos = pos.getNext();
- }
- Contact c = new Contact(name, phone);
- if(prev != null){
- Node<Contact> tmp = new Node<Contact>(c, pos);
- prev.setNext(tmp);
- }else{
- Node<Contact> tmp = new Node<Contact>(c, lst);
- lst=tmp;
- }
- count++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement