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

Spread the post

Delete first half nodes of beginning in Linked List

Suppose linked list contain following nodes [7,8,6,9,1,4,3]. know delete half of beginning element of this linked list.

root_ptr3419687

View insertion process.

Try it Yourself

After delete linked list.

root_ptr3419After delete Half nodes

Test Case

Write an algorithm of satisfied following test cases.

Test case 1 : Even number of linked list nodes.


Test case 2 : Odd number of linked list nodes.


Note that in this case divide linked list two part A and B. A=[7 8 6] B=[1 4 3] and 9 is not part of A and B. part A Contain 3 nodes and part B are contain 3.

Test case 3 : If only one element then. Not delete any nodes.

C program to delete first half node of given linked list.


Output


Code execution: View code execution process.

Stack Areamainroot(pointer)delete_halfremove_node(pointer) NULLroot(pointer)temp(pointer) Heap Areastruct Nodedata (int)= 7next (pointer) struct Nodedata (int)= 8next (pointer) struct Nodedata (int)= 6next (pointer) struct Nodedata (int)= 9next (pointer) struct Nodedata (int)= 1next (pointer) struct Nodedata (int)= 4next (pointer) struct Nodedata (int)= 3next (pointer)= NULL

Note that not given all step of execution process here. view more execution process.

Try it yourself

Spread the post

Recommended Posts: