(mystr)
| 36 | |
| 37 | # 利用栈将字串的字符反转 |
| 38 | def revstring(mystr): |
| 39 | # your code here |
| 40 | s = Stack() |
| 41 | outputStr = '' |
| 42 | for c in mystr: |
| 43 | s.push(c) |
| 44 | while not s.isEmpty(): |
| 45 | outputStr += s.pop() |
| 46 | return outputStr |
| 47 | |
| 48 | # print(revstring('apple')) |
| 49 | # print(revstring('x')) |