<commit_before>require_relative 'linked_list'
# Implement a Queue using a linked list
# Note:
#   1. All operations should take O(1) time
#   2. You'll need to modify the LinkedList to achieve constant
#      time enqueue and dequeue operations.

class Queue
  def initialize
  end

  # Places +item+ at the back of the queue
  def enqueue(item)
  end

  # Removes the item at the front of the queue and returns it
  # Raises an error if the queue is empty
  def dequeue
  end

  # Return the item at the front of the queue without dequeing it
  def peek
  end

  # Return true if the queue is empty and false otherwise
  def empty?
  end

  # Return the number of items on the stack
  def size
  end
end<commit_msg>implement queue with a linked list<commit_after>require_relative 'linked_list'
# Implement a Queue using a linked list
# Note:
#   1. All operations should take O(1) time
#   2. You'll need to modify the LinkedList to achieve constant
#      time enqueue and dequeue operations.

class Queue
  attr_accessor :list

  class UnderflowError < StandardError; end

  def initialize
    @list = LinkedList.new
    @size = 0
  end

  # Places +item+ at the back of the queue
  def enqueue(item)
    @size += 1
    @list.append(item)
  end

  # Removes the item at the front of the queue and returns it
  # Raises an error if the queue is empty
  def dequeue
    raise UnderflowError if empty?

    @size -= 1
    @list.shift
  end

  # Return the item at the front of the queue without dequeing it
  def peek
    @list.head.value
  end

  # Return true if the queue is empty and false otherwise
  def empty?
    @list.head.nil?
  end

  # Return the number of items on the stack
  def size
    @size
  end
end
{'fraction_non_alphanumeric': 0.04947613504074505, 'fraction_numerical': 0.005238649592549476, 'mean_word_length': 2.915717539863326, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3532137', 'n_tokens_mistral': 535, 'n_tokens_neox': 515, 'n_words': 249}