Skip to content

Files

Latest commit

e2692f3 · Feb 8, 2017

History

History
39 lines (24 loc) · 1.21 KB

File metadata and controls

39 lines (24 loc) · 1.21 KB

Queues Exercise

For this exercise you must get the tests to pass.

Part I

  • Write a constructor function for a Queue
    • it should have a size property initialized to 0
    • it should have a first property initialized to null
    • it should have a last property initialized to null
  • Write a constructor function for a Node
    • it should have a value property which is assigned to a value passed as a parameter to the constructor function
    • it should have a next property initialized to null

Implement the following methods on the Queue.prototype

enque

This function adds the value to the end of the queue. This should be an O(1) operation and return the size of the queue.

dequeue

This function removes the value at the beginning of the queue. This should be an O(1) operation and return the value removed.

peek

This function returns the first value in the queue.

print

This function console.log's all the values in the queue.

Part II