Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package sortedintlinkedlist;
- public class SortedIntLinkedList{
- //CODE BROUGHT TO YOU BY MARSOL DAMAN, SOPHOMORE AT OAKLAND GO GRIZZLIES!
- public IntNode listSort(IntNode head){
- //New IntNode list
- int newHead=0;
- IntNode cursor= head;
- IntNode bigToSmall = new IntNode(newHead, null);
- IntNode current = head;
- //While the first List has not reached the last node
- while(head.getLink() != null){
- int min=current.getData();
- while(current.getLink() != null){
- if(current.getData() < current.getLink().getData()){
- if(min <= current.getData());
- min=current.getData();
- current.getLink();
- }
- else
- current.getLink();
- }
- bigToSmall = new IntNode(min, bigToSmall);
- while( cursor.getLink() != null){
- if(cursor.getLink().getData() == min)
- if(cursor.getLink().getLink() == null)
- cursor.setLink(null);
- else
- cursor.removeNodeAfter();
- }
- head.getLink();
- // continues to add biggest all the way to smallest.
- current.getLink();
- }
- return bigToSmall;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement