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

Spread the post

Delete linked list nodes there not contain zig-zag views

Delete all nodes which are not contained in zig-zag view. write an efficient algorithm to solve this program.

Test condition of Zig zag

Conversion on zig zag : Delete node from left to right which are not satisfied Zig zag condition.

For example suppose given linked list contain following nodes [2 7 7 7 6 3 1 10].

root_ptr101367772 Stack Areamainroot(pointer) Heap Areastruct Nodedata (int)= 2next (pointer) struct Nodedata (int)= 7next (pointer) struct Nodedata (int)= 7next (pointer) struct Nodedata (int)= 7next (pointer) struct Nodedata (int)= 6next (pointer) struct Nodedata (int)= 3next (pointer) struct Nodedata (int)= 1next (pointer) struct Nodedata (int)= 10next (pointer)= NULL

After remove

root_ptr10672 Stack Areamainroot(pointer) Heap Areastruct Nodedata (int)= 2next (pointer) struct Nodedata (int)= 7next (pointer) struct Nodedata (int)= 6next (pointer) struct Nodedata (int)= 10next (pointer)= NULL

View code animation

Program for to Delete node which are not in Zig-Zag fashion in linked list. Time complexity O(n).

Output

Submit your solution in comment section.

Spread the post

Recommended Posts: