ruby_collections 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -0
- data/lib/ruby_collections/collections.rb +2 -1
- data/lib/ruby_collections/stack.rb +29 -0
- data/lib/ruby_collections/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb77ec104140f7d24e8026660ed783134ed5fb61
|
4
|
+
data.tar.gz: fd78dfe9362a368154da35a9e18032222e2ecfbb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa6ea383b74b39620fe0502e88c7a65c255b95f895640d35bec2acf5ae0018bc550dba42f27cf3b27cbbd971144ab42771bc3f8887d43da2a27b5d016c513c24
|
7
|
+
data.tar.gz: 58f49231acf86c1f78bedc329cdb85a2e583f9e6cae4e5a39e4b4c9f0d3ca043c8ff388351781c713047892d991de61036089724bfe8f87637c5e7fb089aa786
|
data/README.md
CHANGED
@@ -44,6 +44,24 @@ max_heap.max # => 1
|
|
44
44
|
|
45
45
|
Similarly we can use MinHeap as well.
|
46
46
|
|
47
|
+
### RubyCollections::Stack
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
|
51
|
+
stack = RubyCollections::Stack.new
|
52
|
+
|
53
|
+
stack.push(1) # => [1]
|
54
|
+
|
55
|
+
stack.push(4) # => [4, 1]
|
56
|
+
|
57
|
+
stack.top # => 4
|
58
|
+
|
59
|
+
stack.pop # => 4
|
60
|
+
|
61
|
+
stack.top # => 1
|
62
|
+
|
63
|
+
```
|
64
|
+
|
47
65
|
## Development
|
48
66
|
|
49
67
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module RubyCollections
|
2
|
+
class Stack
|
3
|
+
|
4
|
+
def initialize(arr = [])
|
5
|
+
@arr = arr
|
6
|
+
end
|
7
|
+
|
8
|
+
def size
|
9
|
+
@arr.size
|
10
|
+
end
|
11
|
+
|
12
|
+
def isEmpty?
|
13
|
+
@arr.size.zero?
|
14
|
+
end
|
15
|
+
|
16
|
+
def top
|
17
|
+
@arr[0]
|
18
|
+
end
|
19
|
+
|
20
|
+
def push(e)
|
21
|
+
@arr.unshift(e)
|
22
|
+
end
|
23
|
+
|
24
|
+
def pop
|
25
|
+
@arr.shift
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_collections
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vikash Vikram
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-04-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -60,6 +60,7 @@ files:
|
|
60
60
|
- lib/ruby_collections/collections.rb
|
61
61
|
- lib/ruby_collections/max_heap.rb
|
62
62
|
- lib/ruby_collections/min_heap.rb
|
63
|
+
- lib/ruby_collections/stack.rb
|
63
64
|
- lib/ruby_collections/version.rb
|
64
65
|
- ruby_collections.gemspec
|
65
66
|
homepage: https://github.com/vikashvikram/ruby_collections
|