JSQueue 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/lib/js_queue.rb +35 -0
  3. data/lib/queue_node.rb +8 -0
  4. metadata +45 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6ec8036ff7e1adf1dee14b9bfb7e2916a82f3bed
4
+ data.tar.gz: 405d1ba43932527c1e54ea1ea2fadb2059f4d9ea
5
+ SHA512:
6
+ metadata.gz: c760df615eb8930ab0199fdae960d97c600003e61d727e42bb7c57a355e1ce650d068ceb4c443c7bf70f6286744f283b3c7802292a2728b8f72547fd4f2130d3
7
+ data.tar.gz: 0f2d413c3c5d944196e2b76ceee75fdc1d2bdba8ed424131350bab8cd7def9a3cd6641f8d28589ad0470fbdcb829cf99ff963628362c94f3884e70116bb12e23
data/lib/js_queue.rb ADDED
@@ -0,0 +1,35 @@
1
+ require_relative 'queue_node'
2
+
3
+ class JSQueue
4
+ attr_accessor :first, :last
5
+
6
+ def initialize(data)
7
+ @first = QueueNode.new data
8
+ @last = @first
9
+ end
10
+
11
+ def enqueue(data)
12
+ node = QueueNode.new data
13
+ unless last.nil?
14
+ @last.next = node
15
+ @last = node
16
+ end
17
+ @first = node if @first.nil?
18
+ end
19
+
20
+ def dequeue
21
+ return if @first.nil?
22
+ data = @first.data
23
+ @first = @first.next unless @first.nil?
24
+ @last = nil if @first.nil?
25
+ data
26
+ end
27
+
28
+ def peek
29
+ first.nil? ? nil : first.data
30
+ end
31
+
32
+ def empty?
33
+ first.nil?
34
+ end
35
+ end
data/lib/queue_node.rb ADDED
@@ -0,0 +1,8 @@
1
+ class QueueNode
2
+ attr_accessor :data, :next
3
+
4
+ def initialize(data, next_node=nil)
5
+ @data = data
6
+ @next = next_node
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: JSQueue
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Josh Saint Jacque
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-04-01 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A simple queue data structure in Ruby.
14
+ email: joshsaintjacque@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/js_queue.rb
20
+ - lib/queue_node.rb
21
+ homepage: http://rubygems.org/gems/jsqueue
22
+ licenses:
23
+ - MIT
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.6.6
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: A simple queue data structure in Ruby.
45
+ test_files: []