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

Spread the post

Delete last node from given linked list

Suppose following data are inserting in linked list.

input : 10 20 30 40 50 60 70 80 .

After delete node

Output : 10 20 30 40 50 60 70.

root_ptr8070605040302010

View insertion at beginning.

Try it yourself

After delete linked list.

root_ptr70605040302010

Algorithm:

Use two pointers temp and helper_ptr.temp pointer are point to first node of linked list. while loop are working if temp pointer and temp pointer next node are not NULL. inside while loop assign helper_ptr value is temp and temp pointer are move next memory block. until this process are temp-> next not NULL. After this remove last node temp pointer.

Code execution:

Stack Areamainroot(pointer)delete_lasthelper_ptr(pointer)temp(pointer) Heap Areastruct Nodedata (int)= 10next (pointer) struct Nodedata (int)= 20next (pointer) struct Nodedata (int)= 30next (pointer) struct Nodedata (int)= 40next (pointer) struct Nodedata (int)= 50next (pointer) struct Nodedata (int)= 60next (pointer) struct Nodedata (int)= 70next (pointer) struct Nodedata (int)= 80next (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 find and detect loop of given linked list.

OutPut:

Spread the post

Recommended Posts: