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

Algorithm:

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

Time complexity O(n^2).

Given example:

root_ptr8417611132126689

View insertion process.

Try it yourself

After Perform Bubble sort linked list is.

root_ptr8984666132171211

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.

OutPut:

Spread the post

Recommended Posts: