- Prof. Dancy's Site - Course Site -

Welcome to (*queue audience) "Comment...that...code" with (*queue audience) "Think...Pair...Share"

(game shows were this crazy pre-smarphone dominated thing that families gathered together on evenings to watch on this other crazy thing called cable television)

First Fill out the comments on your own. Second Discuss the comments with a partner. (I will let you know when it's time to discuss with a partner)

Submit your commented code on repl.it. You and your partner should each submit your own assignments even if you settle on identical comments.


### (Type of queue)
class Queue :
	##
	def __init__( self, max_size ) : #(Big-O)
		self._count = 0
		self._front = 0
		self._back = max_size - 1
		self._q_array = Array( max_size )

	##
	def is_empty( self ) : #(Big-O)
		return self._count == 0

	##
	def is_full( self ) : #(Big-O)
		return self._count == len(self._q_array)

	def __len__( self ) : #(Big-O)
		return self._count

	##
	def enqueue( self, item ): #(Big-O)
		#
		assert not self.is_full(), "..."
		max_size = len(self._q_array)
		#
		self._back = (self._back + 1) % max_size
		self._q_array[self._back] = item
		#
		self._count += 1

	##
	def dequeue( self ): #(Big-O)
		#
		assert not self.is_empty(), "..."
		#
		item = self._q_array[ self._front ]
		maxSize = len(self._q_array)
		#
		self._front = (self._front + 1) % max_size
		#
		self._count -= 1
		#
		return item