Martina312

Sort4e

Feb 12th, 2020
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1. public static void swap(SLLNode<Vraboten> prev, SLLNode<Vraboten> tmp, SLLNode<Vraboten> next){
  2.         if(prev!=null){
  3.             prev.succ=next;
  4.         }
  5.         tmp.succ=next.succ;
  6.         next.succ=tmp;
  7.     }
  8.     public static void sort(SLL<Vraboten> list){
  9.         SLLNode<Vraboten> tmp;
  10.         SLLNode<Vraboten> prev;
  11.  
  12.         for(int i=0;i<100;i++){
  13.             tmp=list.getFirst();
  14.             prev=null;
  15.  
  16.             while(tmp.succ!=null){
  17.                 if(tmp.element.getID()<tmp.succ.element.getID()){
  18.                     if(tmp==list.getFirst()){
  19.                         list.setFirst(tmp.succ);
  20.                     }
  21.                     swap(prev,tmp,tmp.succ);
  22.                 }
  23.                 prev=tmp;
  24.                 tmp=tmp.succ;
  25.                 if(tmp==null)
  26.                     break;
  27.             }
  28.         }
  29.         System.out.println(list);
  30.     }
Add Comment
Please, Sign In to add comment