Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. public void sortList() {
  2. Node current = null, index = null;
  3. int temp;
  4. //Check whether list is empty
  5. if(head == null) {
  6. return;
  7. }
  8. else {
  9. //Current will point to head
  10. for(current = head; current.next != null; current = current.next) {
  11. //Index will point to node next to current
  12. for(index = current.next; index != null; index = index.next) {
  13. //If current's data is greater than index's data, swap the data of current and index
  14. if(current.data > index.data) {
  15. temp = current.data;
  16. current.data = index.data;
  17. index.data = temp;
  18. }
  19. }
  20. }
  21. }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement