Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1.  
  2. package sortedintlinkedlist;
  3.  
  4.  
  5.  
  6.  
  7. public class SortedIntLinkedList{
  8. //CODE BROUGHT TO YOU BY MARSOL DAMAN, SOPHOMORE AT OAKLAND GO GRIZZLIES!
  9.  
  10.  
  11. public IntNode listSort(IntNode head){
  12. //New IntNode list
  13. int newHead=0;
  14. IntNode cursor= head;
  15.  
  16. IntNode bigToSmall = new IntNode(newHead, null);
  17. IntNode current = head;
  18. //While the first List has not reached the last node
  19. while(head.getLink() != null){
  20. int min=current.getData();
  21. while(current.getLink() != null){
  22. if(current.getData() < current.getLink().getData()){
  23.  
  24. if(min <= current.getData());
  25.  
  26. min=current.getData();
  27. current.getLink();
  28.  
  29. }
  30. else
  31. current.getLink();
  32. }
  33.  
  34. bigToSmall = new IntNode(min, bigToSmall);
  35. while( cursor.getLink() != null){
  36. if(cursor.getLink().getData() == min)
  37. if(cursor.getLink().getLink() == null)
  38. cursor.setLink(null);
  39. else
  40. cursor.removeNodeAfter();
  41.  
  42. }
  43. head.getLink();
  44.  
  45.  
  46.  
  47. // continues to add biggest all the way to smallest.
  48. current.getLink();
  49.  
  50. }
  51. return bigToSmall;
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement