Learn basic concept of c , c++ and python programming in regularcodes.com

Spread the post

Bubble sort on given linked list

Suppose given linked list contain following nodes.

Input: 89 66 12 32 11 61 17 84

Output: 11 12 17 32 61 66 84 89


Use three pointer temp, help and sort pointers. view function to prform bubble sort.

Time complexity O(n^2).

Given example:


View insertion process.

Try it yourself

After Perform Bubble sort linked list is.


Code execution:

Stack Areamainroot(pointer)bubble_sorthelp(pointer)store(pointer)swap_data (int) =12temp(pointer) Heap Areastruct Nodedata (int)= 11next (pointer) struct Nodedata (int)= 12next (pointer) struct Nodedata (int)= 32next (pointer) struct Nodedata (int)= 17next (pointer) struct Nodedata (int)= 61next (pointer) struct Nodedata (int)= 66next (pointer) struct Nodedata (int)= 84next (pointer) struct Nodedata (int)= 89next (pointer)= NULL

Note that not given all step of execution process here.View How to insert linked list element and so on.

Try it yourself

C program to perform bubble sort of given linked list.


Spread the post

Recommended Posts: