English

Write a python program to check whether the given string is palindrome or not, using deque. (Hint : refer to algorithm 4.1) - Computer Science (Python)

Advertisements
Advertisements

Question

Write a python program to check whether the given string is palindrome or not, using deque. (Hint : refer to algorithm 4.1)

Answer in Brief

Solution

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
Introduction to Deque
  Is there an error in this question or solution?
Chapter 4: Queue - Exercise [Page 66]

APPEARS IN

NCERT Computer Science [English] Class 12
Chapter 4 Queue
Exercise | Q 8. | Page 66
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×