Computer Science‎ > ‎

### Basic Data Structures in Ruby - The Queue

The general idea of the Queue data structure ( and C program code ) is available here : Data Structures: Queues ( with C Program source code)
In this program, we take a quick look at Queues as provided by Ruby.

# Queues are a First in First Out Data Structure
# Ruby provides you with synchronoized/thread-safe queues

testQueue = Queue.new
testQueue.enq(10)
puts "Enqueing 10"
testQueue.enq(12)
puts "Enqueing 12"
testQueue.enq(13)
puts "Enqueing 13"

while   ! testQueue.empty?
popped = testQueue.deq
puts "Popped : " + popped.to_s
end

=begin
Sample Output:
~/work/ruby_tutorials\$ ruby queue.rb
Enqueing 10
Enqueing 12
Enqueing 13
Popped : 10
Popped : 12
Popped : 13
=end

Check out some of our other Ruby Tutorials :

## Introduction to Ruby

 Introduction to Ruby and some playing around with the Interactive Ruby Shell (irb) Introduction to Ruby - Conditional statements and Modifiers: If-then, Unless, Case Introduction to Ruby Comments - Single and Multi-Line comments Introduction to Ruby Loops - Using While, Until, For, Break, Next , Redo, Retry Introduction to Ruby - Arrays - Sorting, Filtering (Select), Transforming, Multi-Dimensional Arrays Introduction to Ruby - Strings Introduction to Ruby - Making a Script Executable Introduction to Ruby - Regular Expressions, Match, Scan Introduction to Ruby - Computing Factorials Recursively : An Example of Recursion Introduction to Ruby - Binomial Coefficients (nCr) : An Example of Recursion Introduction to Ruby - Computing a Power Set : An Example of Recursion Introduction to Ruby - Towers of Hanoi : An Example of Recursion Introduction to Ruby - Strings: Substitution, Encoding, Built-In Methods

## Basic Data Structures With Ruby

 Basic Data Structures in Ruby - Insertion Sort Basic Data Structures in Ruby - Selection Sort Basic Data Structures in Ruby - Merge Sort Basic Data Structures in Ruby - Quick Sort Functional Programming with Ruby Basic Data Structures in Ruby - Stack Basic Data Structures in Ruby - The Queue Basic Data Structures in Ruby - Linked List - ( A Simple, Singly Linked List) Basic Data Structures in Ruby - Binary Search Tree