I
I
igoodmood2016-02-26 21:06:45
Python
igoodmood, 2016-02-26 21:06:45

How to use deca to change the letters of a word backwards?

The functions "popBack" and "pushFront" will be used, but how to make them take each element (letters) and rearrange them?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Evgeniy _, 2016-02-26
@GeneD88

from collections import deque
def rev(poly):
    d = deque()
    d.extendleft(poly)
    return poly == ''.join(d)

A
Alexey P, 2016-02-26
@ruddy22

Algorithm:
1. We represent the string as an array of characters
2. We create a stack structure
3. We iteratively push the array onto the stack using pushFront
4. Iteratively take letters from the stack using popBack
5. Glue the array into a string

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question