Advertisement
Parasect

Untitled

Mar 20th, 2015
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.84 KB | None | 0 0
  1.   public void addContact(String name, String phone) {
  2.         Node<Contact> pos = lst;
  3.         while(pos != null && name.equals(pos.getInfo().getName())){
  4.             pos = pos.getNext();
  5.         }
  6.         if (pos != null){
  7.             pos.getInfo().setPhone(phone);
  8.         }else{
  9.             pos = lst;
  10.             Node<Contact> prev = null;
  11.             while(pos != null && name.compareTo(pos.getInfo().getName())>0){
  12.                 prev = pos;
  13.                 pos = pos.getNext();
  14.             }
  15.             Contact c = new Contact(name, phone);
  16.             if(prev != null){
  17.                 Node<Contact> tmp = new Node<Contact>(c, pos);
  18.                 prev.setNext(tmp);
  19.             }else{
  20.                 Node<Contact> tmp = new Node<Contact>(c, lst);
  21.                 lst=tmp;
  22.             }
  23.             count++;
  24.         }
  25.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement