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

Spread the post

Move a given occurrences at end of linked list

Given a linked list and Move a given occurrences at end of linked list. suppose linked list contain following nodes[1, 2, 1, 4, 5, 3, 7, 1, 9, 10].

root_ptr10917354121

Try it Yourself

View pointers and nodes.

Stack Areamainoccurrences (int) ? root(pointer) Heap Areastruct Nodedata (int)= 1next (pointer) struct Nodedata (int)= 2next (pointer) struct Nodedata (int)= 1next (pointer) struct Nodedata (int)= 4next (pointer) struct Nodedata (int)= 5next (pointer) struct Nodedata (int)= 3next (pointer) struct Nodedata (int)= 7next (pointer) struct Nodedata (int)= 1next (pointer) struct Nodedata (int)= 9next (pointer) struct Nodedata (int)= 10next (pointer)= NULL

Try it Yourself

Example : Move all occurrence 1 to end.

root_ptr10973542111

visualize execution process.

Stack Areamainoccurrences (int) =1root(pointer) Heap Areastruct Nodedata (int)= 1next (pointer)= NULLstruct Nodedata (int)= 2next (pointer) struct Nodedata (int)= 1next (pointer) struct Nodedata (int)= 4next (pointer) struct Nodedata (int)= 5next (pointer) struct Nodedata (int)= 3next (pointer) struct Nodedata (int)= 7next (pointer) struct Nodedata (int)= 1next (pointer) struct Nodedata (int)= 9next (pointer) struct Nodedata (int)= 10next (pointer)

Try it Yourself

Accepted Output

C program to Move a given occurrence to end of linked list . Iterative approach.


Output

Spread the post

Recommended Posts: