retagged by
378 views

1 Answer

1 1 vote

You dont need necessarily require an auxilary array for sorting. This is a pseudo code for bubble sort:

function bubbleSort(head):
    if head is null:
        return

    swapped = true
    lptr = null

    while swapped is true:
        swapped = false
        ptr1 = head

        while ptr1.next is not lptr:
            if ptr1.data > ptr1.next.data:
                swap(ptr1.data, ptr1.next.data)
                swapped = true
            ptr1 = ptr1.next

        lptr = ptr1

 

This is what I saw in wikipedia regarding merge sort:

Merge sort is often the best choice for sorting a linked list: in this situation it is relatively easy to implement a merge sort in such a way that it requires only Θ(1) extra space, and the slow random-access performance of a linked list makes some other algorithms (such as quicksort) perform poorly, and others (such as heapsort) completely impossible.

edited by
Position:
Show:

Related questions

1 1 vote
0 0 answers
336
336 views
ASH1198 asked Dec 16, 2025
336 views
In a 32-bit machine we subdivide the virtual address into 4 pieces as follows:8-bit 4-bit 8-bit 12-bitWe use a 3-level page table, such that the first 8 bits are...
0 0 votes
0 0 answers
1.3k
1.3k views
ayush201 asked Dec 30, 2018
1,333 views
A weight-balanced tree is a binary tree in which for each node. The number of nodes in the left sub tree is at least half and at most twice the number of nodes in the rig...
0 0 votes
0 0 answers
1.9k
1.9k views
ayush201 asked Dec 7, 2018
1,936 views
Q.47. How many minimum relation tables are required which satisfy 1NF? A 2, 2, and 1 respectivelyB 2, 2, and 2 respectivelyC 1, 2, and 1 respectivelyD 1, 1, and 1 respect...
0 0 votes
0 0 answers
2.4k
2.4k views
akankshadewangan24 asked Sep 22, 2018
2,422 views
How to solve thishttps://www.geeksforgeeks.org/wp-content/uploads/gq/2016/02/GATECS201612.png