#20 Recursive Function to Check if String is Palindrome|Data Structure and Algorithm|STUDY LIKE PRO|

preview_player
Показать описание


STUDY LIKE PRO is an educational channel for all students who are Interested in Learning the following subject and topics such as
#JAVA PROGRAMMING
#DATA STRUCTURES
#ALGORITHM
#Introduction
#Mathematics
#Bit Magic
#Recursion
#Arrays
#Searching
#Sorting
#Matrix
#Hashing
#Strings
#Linked List
#Stack
#Queue
#Tree
#Binary Search Tree
#Heap
#Graph
#Greedy
#Backtracking
#Dynamic Programming
#Graph (Advanced)
#Trie
#Segment-Tree
#Disjoint Set

Рекомендации по теме
Комментарии
Автор

very detailed explanation bro...especially at 3:19, i was stuck at this for few days..thanks a lot

hannanhub
Автор

C++ code for the above approach:

#include<bits/stdc++.h>
using namespace std;

bool palindrome(string &str, int first_index, int last_index){
if(first_index == last_index)
return true;


if(first_index > last_index)
return true;

if(str[first_index] != str[last_index])
return false;

palindrome(str, first_index+1, last_index-1);

}
int main(){
string str;
getline(cin, str);

if(palindrome(str, 0, str.length()-1))
cout<<"Palindrome String";
else{
cout<<"Not a Palindrome String";
}

}

ankitkumarmishra
Автор

It is veryy good but if we want to don't use array and string, what should we do?

seyedehfatemehmousavi
Автор

bool isPalindrome(int[], int, int);
int main()
{
int array[5] = { 5, 7, 2, 7, 5 };
int length = sizeof(array) / sizeof(array[0]);
int mid = (length - 1) / 2;
cout << isPalindrome(array, length, mid);
return 0;
}
bool isPalindrome(int arr[], int n, int m) {
int i = 0;
if (n == m)
return true;
else
if (arr[i] == arr[n - 1])
i = i + 1;
return true;
isPalindrome(arr + 1, n - 1, m);
}
doesnt work :(

abrahanshahzad