Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void sortList() {
- Node current = null, index = null;
- int temp;
- //Check whether list is empty
- if(head == null) {
- return;
- }
- else {
- //Current will point to head
- for(current = head; current.next != null; current = current.next) {
- //Index will point to node next to current
- for(index = current.next; index != null; index = index.next) {
- //If current's data is greater than index's data, swap the data of current and index
- if(current.data > index.data) {
- temp = current.data;
- current.data = index.data;
- index.data = temp;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement