Class: Containers::MinHeap

### Home Classes Methods

### In Files

- lib/containers/heap.rb

### Parent

Containers::Heap

### Methods

- ::new
- #min
- #min!

### Files

- Makefile
- Makefile
- Makefile
- Makefile
- Makefile

### Class/Module Index

Quicksearch

- Containers
- Containers::CBst
- Containers::CDeque
- Containers::CRBTreeMap
- Containers::CSplayTreeMap
- Containers::Heap
- Containers::KDTree
- Containers::MaxHeap
- Containers::MinHeap
- Containers::PriorityQueue
- Containers::Queue
- Containers::RubyDeque
- Containers::RubyDeque
- Containers::RubyRBTreeMap
- Containers::RubyRBTreeMap
- Containers::RubySplayTreeMap
- Containers::RubySplayTreeMap
- Containers::Stack
- Containers::SuffixArray
- Containers::Trie
- Object
- Object::Deque
- Object::RBTreeMap
- Object::SplayTreeMap
- Algorithms
- Algorithms::Search
- Algorithms::String

No matching classes.

# Containers::MinHeap

A MinHeap is a heap where the items are returned in ascending order of key value.

### Public Class Methods

new(ary) → new_heap click to toggle source

Creates a new MinHeap with an optional array parameter of items to insert into the heap. A MinHeap is created by calling Heap.new { |x, y| (x <=> y) == -1 }, so this is a convenience class.

    minheap = MinHeap.new([1, 2, 3, 4])
    minheap.pop #=> 1
    minheap.pop #=> 2

    # File lib/containers/heap.rb, line 474
    def initialize(ary=[])
      super(ary) { |x, y| (x <=> y) == -1 }
    end

### Public Instance Methods

min → value click to toggle source
min → nil

Returns the item with the smallest key, but does not remove it from the heap.

    minheap = MinHeap.new([1, 2, 3, 4])
    minheap.min #=> 1

    # File lib/containers/heap.rb, line 486
    def min
      self.next
    end

min! → value click to toggle source
min! → nil

Returns the item with the smallest key and removes it from the heap.

    minheap = MinHeap.new([1, 2, 3, 4])
    minheap.min! #=> 1
    minheap.size #=> 3

    # File lib/containers/heap.rb, line 499
    def min!
      self.pop
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.