Advertisements
Advertisements
प्रश्न
Write a python program to check whether the given string is palindrome or not, using deque. (Hint : refer to algorithm 4.1)
संक्षेप में उत्तर
Advertisements
उत्तर
Check given string is palindrome or not using deque.
def insertRear(que, ch):
que.append(ch)
def deletionFront(que):
if que != []:
return que.pop(0)
def deletionRear(que):
if que != []:
return que.pop()
def palindromeCheck(string):
palindrome = True
for ch in string:
insertRear(strque, ch)
while len(strque) > 1 and palindrome:
first = deletionFront(strque)
last = deletionRear(strque)
if first != last:
palindrome = False
return palindrome
#__main__
strque = []
string = input("Enter a String : ")
if palindromeCheck(string):
print("Given String ", string, "is a PALINDROME")
else:
print("Given string ", string, "is NOT a PALINDROME")
Output:
Enter a String : naman
Given naman is a PALINDROME
Enter a String : tanmay
Given tanmay is NOT a PALINDROME
shaalaa.com
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
