File tree 2 files changed +27
-4
lines changed
2 files changed +27
-4
lines changed Original file line number Diff line number Diff line change @@ -43,15 +43,16 @@ Get the top item from the stack. Sometimes called peek.
43
43
Base. first (s:: Stack ) = last (s. store)
44
44
Base. last (s:: Stack ) = first (s. store)
45
45
46
- function Base. push! (s:: Stack , x)
47
- push! (s. store, x)
48
- return s
49
- end
46
+ Base. push! (s:: Stack , x) = (push! (s. store, x); s)
47
+ Base. pushfirst! (s:: Stack , x) = (pushfirst! (s. store, x); s)
50
48
51
49
Base. pop! (s:: Stack ) = pop! (s. store)
50
+ Base. popfirst! (s:: Stack ) = popfirst! (s. store)
52
51
53
52
Base. empty! (s:: Stack ) = (empty! (s. store); s)
54
53
54
+ Base. collect (s:: Stack ) = collect (s. store)
55
+
55
56
Base. iterate (st:: Stack , s... ) = iterate (Iterators. reverse (st. store), s... )
56
57
57
58
Iterators. reverse (s:: Stack{T} ) where {T} = DequeIterator {T} (s. store)
Original file line number Diff line number Diff line change 38
38
@test isempty (s) == (i == n)
39
39
@test length (s) == n - i
40
40
end
41
+
42
+ for i = 1 : n
43
+ pushfirst! (s, i)
44
+ @test first (s) == 1
45
+ @test last (s) == i
46
+ @test ! isempty (s)
47
+ @test length (s) == i
48
+ end
49
+
50
+ @test collect (s) == collect (n: - 1 : 1 )
51
+
52
+ for i = 1 : n
53
+ x = popfirst! (s)
54
+ @test x == n - i + 1
55
+ if i < n
56
+ @test first (s) == 1
57
+ else
58
+ @test_throws ArgumentError first (s)
59
+ end
60
+ @test isempty (s) == (i == n)
61
+ @test length (s) == n - i
62
+ end
41
63
end
42
64
43
65
@testset " ==" begin
You can’t perform that action at this time.
0 commit comments