मराठी

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

प्रश्न

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

थोडक्यात उत्तर

उत्तर

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
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 4: Queue - Exercise [पृष्ठ ६६]

APPEARS IN

एनसीईआरटी Computer Science [English] Class 12
पाठ 4 Queue
Exercise | Q 8. | पृष्ठ ६६
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×