$30
CSC148
Quiz 4: Abstract Data Types
Read the code for the function unravel.
1 def unravel ( nested : list ) -> None :
2 """ Print elements of <L> and its nested sub - lists in " level order ".
3 """
4 q = Queue ()
5 for e in nested :
6 q . enqueue ( e )
7
8 while not q . is_empty () :
9 i = q . dequeue ()
10 if not isinstance (i , list ) :
11 print ( i )
12 else :
13 for e in i :
14 q . enqueue ( e )
For this quiz, when asked to draw the state of a queue, draw it with the front labeled, and queue elements separated by
arrows. For example, if we enqueue 10, then 20, then 30, draw the queue like this: front → 10 → 20 → 30
You may write front → only once and omit it afterwards. This is to show that you know which side is the front of the
queue.
Consider the following code snippet that uses a queue:
1 >>> L = [ 'a ' , [ 'b ' , [ 'c ', 'd '] , 'e ' , 'f '] , [ 'g ' , 'h ' , 'i '] , 'j ']
2 >>> unravel ( L )
1. Draw the state of q during the function call unravel(L) at line 7 in unravel.
2. For each iteration of the while loop in unravel, write/draw two things:
(i) What, if any, output is printed at line 11.
(ii) The state of q at the end of the iteration (right after line 15).
Output (if any) State of q