Class: RubyPriorityQueue::PriorityQueue::Node

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#itemObject

Returns the value of attribute item.



32
33
34
# File 'lib/ruby_priority_queue.rb', line 32

def item
  @item
end

#priorityObject

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