Sort a linked list using bubble sort

Merge sort looks like a best choice for sorting the linked list.At a first appearance, merge sort may be a good selection since the middle element is required to subdivide the given list into 2 halves, but we can easily solve this problem by moving the nodes alternatively to 2 lists. We have discussed the sorting options for linked list here. Here we will discuss about bubble sort Pseudocode for bubble sort: [Read More]

Bubble sort on double linked list

 Following can be the pseudocode:

public void bubbleSort() {  
    boolean done = false;  
    while (!done) {  
        Node cur = head;  
        done = true;  
        while(cur != tail) {  
            if (cur.getNext().getCount()>cur.getCount()) {  
                swap(cur.getNext(),cur);  
                done=false;  
            }  
            cur = cur.getNext();  
        }  
    }  
}  

Thanks.
Source : stackoverflow

What's the fastest algorithm for sorting a linked list?

Merge sort is the best choice. At a first appearance, merge sort may be a good selection since the middle element is required to subdivide the given list into 2 halves, but we can easily solve this problem by moving the nodes alternatively to 2 lists. It is reasonable to expect that you cannot do any better than O(N log N) in running time, whenever we use comparison based sorts. [Read More]

Bubble sort

The sorting problem Input: Array of numbers , unsorted. Eg. Output : Same numbers sorted in some order, say increasing order. Eg. What is Bubble Sort? The bubble sort works by comparing each item in the list with the item next to it, and swapping them if required. The algorithm repeats this process until it makes a pass all the way through the list without swapping any items (in other words, all items are in the correct order). [Read More]