हिंदी

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×