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)
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
APPEARS IN
RELATED QUESTIONS
An arrangement in which addition and removal of elements can happen from any end is known as ______.
A dequeue is also known as ______.
By adding and deleting the elements in a deque from the same end you can make it work like a ______.
By adding and deleting the elements in a deque from the opposite ends you can make it work like a ______.
Which operation is used to insert an element in the front of the dequeue?
Which operation removes an element from the front of the dequeue?
Which operation removes an element from the rear of the dequeue?
Which operation inserts a new element at the rear of the dequeue?
Deque supports stack but not queue.
How is queue data type different from deque data type?
Deletion of elements is performed from ______ end of the queue.
______ is a data structure where elements can be added or removed at either end, but not in the middle.
A deque contains ‘z’, ’x’, ’c’, ’v’ and ‘b’. Elements received after deletion are ‘z’, ’b’, ’v’, ’x’ and ‘c’. ______ is the sequence of deletion operation performed on deque.