MCPcopy Index your code
hub / github.com/geekcomputers/Python / reverse

Function reverse

stack.py:36–55  ·  view source on GitHub ↗
(string)

Source from the content-addressed store, hash-verified

34
35# A stack based function to reverse a string
36def reverse(string):
37 n = len(string)
38
39 # Create a empty stack
40 stack = createStack()
41
42 # Push all characters of string to stack
43 for i in range(0, n, 1):
44 push(stack, string[i])
45
46 # Making the string empty since all
47 # characters are saved in stack
48 string = ""
49
50 # Pop all characters of string and
51 # put them back to string
52 for i in range(0, n, 1):
53 string += pop(stack)
54
55 return string
56
57
58# Driver program to test above functions

Callers 1

stack.pyFile · 0.85

Calls 3

createStackFunction · 0.70
pushFunction · 0.70
popFunction · 0.70

Tested by

no test coverage detected