Class: RubyPriorityQueue::PriorityQueue::Node
- Inherits:
-
Object
- Object
- RubyPriorityQueue::PriorityQueue::Node
- Includes:
- Comparable
- Defined in:
- lib/ruby_priority_queue.rb
Overview
The Node class represents an element in the priority queue. Each node contains an item and its associated priority.
The Node class includes the Comparable module to allow comparison between nodes based on their priority.
Instance Attribute Summary collapse
-
#item ⇒ Object
Returns the value of attribute item.
-
#priority ⇒ Object
Returns the value of attribute priority.
Instance Method Summary collapse
-
#<=>(other) ⇒ Integer
Compares this node with another node based on their priority.
-
#initialize(item, priority) ⇒ Node
constructor
Initializes a new Node with the given item and priority.
Constructor Details
#initialize(item, priority) ⇒ Node
Initializes a new Node with the given item and priority.
38 39 40 41 |
# File 'lib/ruby_priority_queue.rb', line 38 def initialize(item, priority) @item = item @priority = priority end |
Instance Attribute Details
#item ⇒ Object
Returns the value of attribute item.
32 33 34 |
# File 'lib/ruby_priority_queue.rb', line 32 def item @item end |
#priority ⇒ Object
Returns the value of attribute priority.
32 33 34 |
# File 'lib/ruby_priority_queue.rb', line 32 def priority @priority end |
Instance Method Details
#<=>(other) ⇒ Integer
Compares this node with another node based on their priority.
47 48 49 |
# File 'lib/ruby_priority_queue.rb', line 47 def <=>(other) priority <=> other.priority end |