MCPcopy
hub / github.com/careercup/ctci / sort

Method sort

java/Chapter 3/Question3_6/Question.java:60–70  ·  view source on GitHub ↗
(Stack<Integer> s)

Source from the content-addressed store, hash-verified

58 }
59
60 public static Stack<Integer> sort(Stack<Integer> s) {
61 Stack<Integer> r = new Stack<Integer>();
62 while(!s.isEmpty()) {
63 int tmp = s.pop();
64 while(!r.isEmpty() && r.peek() > tmp) {
65 s.push(r.pop());
66 }
67 r.push(tmp);
68 }
69 return r;
70 }
71
72 public static void main(String [] args) {
73 for (int k = 1; k < 100; k++) {

Callers 3

fMethod · 0.45
getSortedArrayMethod · 0.45

Calls 4

isEmptyMethod · 0.95
popMethod · 0.95
peekMethod · 0.95
pushMethod · 0.95

Tested by

no test coverage detected