Write a recursive function palindrome_list(arglist), where arglist is a list, th
ID: 3813782 • Letter: W
Question
Write a recursive function palindrome_list(arglist), where arglist is a list, that returns True if and only if arglist is a palindrome, i.e., is the same sequence of elements whether it is traversed forwards from the first element or backwards from the last element. Solve this problem using recursion. You are allowed to use only the following programming constructs: if statements. return statements; assignment; recursive function calls (but not to helper functions); comparison operations (==, !=, etc.); list indexing and slicing; Boolean operations (and, or, not). Solutions that go outside these constructs, e.g., by using for/while loops or list comprehensions, will not get credit. 1. Palindrome_list. (['aa', 'bb', 'bb', 'aa']) return value: True 2. Palindrome_list (['aa', 'bb', ", 'bb', ", 'aa']) return value: False 3. Palindrome_list (['aa', 'bb', 'aa', "]) return value: False 4. Palindrome_list ([]) return value: True 5. Palindrome_list ([1, 2, 3, 2, 1]) return value: True 6. Palindrome_list ([1, 2, 3, 2]) return value: False 7. Palindrome_list ([1, 2], [3, 4, 3], [1, 2]]) return value: TrueExplanation / Answer
#include<stdio.h>
#include<string.h>
int Palindrome_list (char arglist,int length)
{
if(length<=0)
return1;
if(arglist[0]==arglist[length-1])
{
return Palindrome_list(arglist+1,length-2) //recursive call function which is called itself
}
else return 0;
}
int main(void)
{
int string;
char arglist[100];
printf("enter the string");
gets(arglist);
int length=strlen(arglist);
result=Palindrome_list(arglist,length);//the function is called here
if result==1
return true;
else
return false;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.