bubble sort in linked list code example
Example 1: bubble sort on a doubly linked list
public void sortList() {
Node current = null, index = null;
int temp;
if(head == null) {
return;
}
else {
for(current = head; current.next != null; current = current.next) {
for(index = current.next; index != null; index = index.next) {
if(current.data > index.data) {
temp = current.data;
current.data = index.data;
index.data = temp;
}
}
}
}
}
Example 2: bubble sort linked list java
public static void main(String[] args){
LinkedList linkedlist = new LinkedList()