mirror of
https://github.com/TheAlgorithms/Ruby
synced 2024-12-27 21:58:57 +01:00
Add references links
This commit is contained in:
parent
42b1a00dfd
commit
888ad29ba2
1 changed files with 8 additions and 4 deletions
|
@ -1,5 +1,5 @@
|
||||||
# A queue is like a waiting list.
|
# A queue is like a waiting list.
|
||||||
# Imagine you’re waiting in line to buy the latest Android product
|
# Imagine you are waiting in line to buy the latest Android product
|
||||||
# or getting a parking ticket. These are queues!
|
# or getting a parking ticket. These are queues!
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -7,9 +7,9 @@
|
||||||
# 1. An array can behave like a Queue if you use the right methods.
|
# 1. An array can behave like a Queue if you use the right methods.
|
||||||
#
|
#
|
||||||
# These methods are:
|
# These methods are:
|
||||||
# - unshift (or prepend with Ruby 2.5+): when you unshift,
|
# - unshift: when you unshift, you are adding one item to the queue
|
||||||
# you are adding one item to the queue
|
|
||||||
# - pop
|
# - pop
|
||||||
|
#
|
||||||
|
|
||||||
class ArrayQueue
|
class ArrayQueue
|
||||||
def initialize(queue = [])
|
def initialize(queue = [])
|
||||||
|
@ -53,6 +53,8 @@ puts(queue.peek)
|
||||||
# Ruby has a proper thread-safe, blocking, Queue class.
|
# Ruby has a proper thread-safe, blocking, Queue class.
|
||||||
# You can use this queue for coordinating work in a multi-threaded program.
|
# You can use this queue for coordinating work in a multi-threaded program.
|
||||||
#
|
#
|
||||||
|
# Reference: https://ruby-doc.org/core-2.5.0/Queue.html
|
||||||
|
#
|
||||||
|
|
||||||
que = Queue.new
|
que = Queue.new
|
||||||
|
|
||||||
|
@ -71,9 +73,11 @@ que.pop
|
||||||
|
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# 3. How to Use A Sized Queue
|
# 3. How to Use a Ruby SizedQueue
|
||||||
# A sized queue is the same as a regular queue but with a size limit.
|
# A sized queue is the same as a regular queue but with a size limit.
|
||||||
#
|
#
|
||||||
|
# Reference: https://ruby-doc.org/core-2.5.0/SizedQueue.html
|
||||||
|
#
|
||||||
|
|
||||||
que = SizedQueue.new(5)
|
que = SizedQueue.new(5)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue