MCPcopy Create free account
hub / github.com/careercup/ctci / sort_stack

Method sort_stack

python/Chapter 3/Question3_6/ChapQ3.6.py:9–19  ·  view source on GitHub ↗
(s)

Source from the content-addressed store, hash-verified

7 return len(self) == 0
8
9 def sort_stack(s):
10 r = Stack()
11 while not s.empty():
12 tmp = s.pop()
13 while not r.empty() and r.peak() > tmp:
14 s.push(r.pop())
15 r.push(tmp)
16 while not s.empty() and s.peak() >= r.peak():
17 #warning, >= here
18 r.push(s.pop())
19 return r
20
21#testing
22from random import randrange

Callers 1

ChapQ3.6.pyFile · 0.80

Calls 5

emptyMethod · 0.95
popMethod · 0.95
peakMethod · 0.95
pushMethod · 0.95
StackClass · 0.70

Tested by

no test coverage detected