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

Spread the post

Remove half nodes from end of linked list

Suppose linked list contain following nodes [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].Our goal is to remove half nodes from end of linked list.

Accepted Output

If Odd number of linked list node. example [1, 2, 3, 4, 5].

First half nodes 1,2,3

Second half nodes 4,5

root_ptr10987654321

Try it Yourself

View pointers and nodes.

Stack Areamainroot(pointer)show_datatemp(pointer) Heap Areastruct Nodedata (int)= 1next (pointer) struct Nodedata (int)= 2next (pointer) struct Nodedata (int)= 3next (pointer) struct Nodedata (int)= 4next (pointer) struct Nodedata (int)= 5next (pointer) struct Nodedata (int)= 6next (pointer) struct Nodedata (int)= 7next (pointer) struct Nodedata (int)= 8next (pointer) struct Nodedata (int)= 9next (pointer) struct Nodedata (int)= 10next (pointer)= NULL

Try it Yourself

Function to delete second half nodes.

After Delete Last half nodes.

root_ptr54321

Process to delete elements.

Stack Areamainroot(pointer)delete_last_halfmid_node(pointer) NULLroot(pointer)temp(pointer) NULL Heap Areastruct Nodedata (int)= 1next (pointer) struct Nodedata (int)= 2next (pointer) struct Nodedata (int)= 3next (pointer) struct Nodedata (int)= 4next (pointer) struct Nodedata (int)= 5next (pointer)= NULL

C program to remove (delete) end half nodes of linked list. Iterative approach.


Output

Spread the post

Recommended Posts: