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

Spread the post

Palindrome linked list find

Following method to find palindrome in linked list.

1) Using stack

2) Using compiler stack (recursion)

Given few example of palindrome in linked list linked list

Example 1:

Palindrome Example

Try it yourself

found palindrome in this linked list.

Example 2: Palindrom word

root_ptrLEVEL

LEVEL is palindrom word.

found palindrome in this linked list.

Algorithm: Using stack .

C program to palindrome finder using stack.

Output

Code execution: view code execution process.

Stack Areamainroot(pointer)stack_top(pointer)temp(pointer) NULLfind_palindromelinked_ptr(pointer)stack_ptr(pointer)status (int) =1popdelete_node(pointer) NULLtemp(pointer) Heap Areastruct Nodedata (int)= 1next (pointer) struct Nodedata (int)= 4next (pointer) struct Nodedata (int)= 3next (pointer) struct Nodedata (int)= 3next (pointer) struct Nodedata (int)= 4next (pointer) struct Nodedata (int)= 1next (pointer)= NULLstruct Stacknext (pointer)= NULLnode (pointer) struct Stacknext (pointer) node (pointer)

Note that not given all step of execution process here.View How to insert Linked list node and so on.

Try it yourself

Algorithm 2: Another Methode using Recursion

C program to palindrome finder.

Output:

View code execution:

Stack Areamaincheck(pointer)root(pointer)status (int) =1palindromeend(pointer)start(pointer)status(pointer)palindromeend(pointer)start(pointer)status(pointer)palindromeend(pointer)start(pointer)status(pointer)palindromeend(pointer)start(pointer)status(pointer)palindromeend(pointer)start(pointer)status(pointer)palindromeend(pointer)start(pointer)status(pointer)palindromeend(pointer)start(pointer) NULLstatus(pointer) Heap Areastruct Nodedata (int)= 1next (pointer) struct Nodedata (int)= 4next (pointer) struct Nodedata (int)= 3next (pointer) struct Nodedata (int)= 3next (pointer) struct Nodedata (int)= 4next (pointer) struct Nodedata (int)= 1next (pointer)= NULL

Note that not given all step of execution process here.View How to insert Linked list node and so on.

Try it yourself

Spread the post

Recommended Posts: