Harvey James
Q1:
Queue Operation Queue contents Return value
q.isEmpty() [] True
q.enQueue(“Blue”) [“Blue”] (none)
q.enQueue(“Red”) [“Blue”,”Red”] (none)
q.enQueue(“Green”) [“Blue”,”Red”,”Green”] (none)
q.isFull() [] False
q.isEmpty() [“Blue”,”Red”,”Green”] False
q.deQueue() [”Red”,”Green”] “Blue”
q.enQueue(“Yellow”) [”Red”,”Green”,”Yellow”] (none)
Q2: ←[Jason, Milly, Bob, Adam, ←, ] 4 names, 2 spaces
[ , ←, Bob, Adam, Jack, ←] 3 names, 3 spaces
Q3:
← ←
←Ali Ben Charlie Davina Enid Fred ←
Greg ← ←Davina Enid Fred
Q4:
In a circular queue insertion and deletion can happen simultaneously unlike in linear queues where
they are two different steps.
Q5:
When it has a time limit/is time sensitive. When it is not time sensitive.
1. A)
Because it does not have the limitations of a linear queue in that all spaces in the queue, such as
the front, can be filled if they are empty.
B)
A dynamic data structure is a collection of data in memory that has the ability to grow or shrink
in size. It is useful for implementing queues when the size of the queue is not known in advance.
It can do this with the aid of the heap, a portion of memory from which space is automatically
allocated or de-allocated as required.
Harvey James
C)
i)
←Job1 Job2 Job3 Job4 Job5 ←
Job6 ← ←Job3 Job4 Job5
2.
A)Because you are taking cards from the front and adding to the back of the stack.
b) i) Front = 11, Rear = 10, Queuesize = 52
ii)
Harvey James
#harvey 07-05-2018 card dealer ace 2-10 H, D, S, C. Joker Queen King
import random
def deal_initilase():
#on first deal, front will become 1, rear becomes 0
global shuff_deck, front, rear #initilases variables
print("You got: {}".format(shuff_deck[front])) #outputs your card
if front == 51: #used to modify pointers, allows for switching start and end of
stack
front = 0
else:
Harvey James
front+=1
if rear == 51:
rear = 0
else:
rear +=1
validate(input("Would you like to me to deal you a card? \n")) #asks again
def validate(inp):
if inp[0].lower() == "y":
deal_initilase() #calls function that deals cards
elif inp[0].lower() == "n":
inp = input("Would you like to me to deal you a card? \n")
return validate(inp)
else:
inp = input("Invalid input, try again: \n")
return validate(inp)
front = 0 #will change
rear = 51 #will change
hearts = ["Ace-Hearts"]
diamonds = ["Ace-Diamonds"]
spades = ["Ace-Spades"]
clubs = ["Ace-Clubs"]
hearts+=["{}-Hearts".format(i) for i in range(2, 11)]
diamonds+=["{}-Diamonds".format(i) for i in range(2, 11)]
spades+=["{}-Spades".format(i) for i in range(2, 11)]
clubs+=["{}-Clubs".format(i) for i in range(2, 11)]
hearts+=["Joker-Hearts","Queen-Hearts","King-Hearts"]
diamonds+=["Joker-Diamonds","Queen-Diamonds","King-Diamonds"]
spades+=["Joker-Spades","Queen-Spades","King-Spades"]
clubs+=["Joker-Clubs","Queen-Clubs","King-Clubs"]
full_deck = hearts + diamonds + spades + clubs #combines all types into one 52 card deck
shuff_deck = random.sample(full_deck, 52) #shuffles deck
print("Ordered deck: {}".format(full_deck)) #outputs ordered deck
print("Shuffled deck: %s" % shuff_deck) #outputs shuffled deck (EOF error when use
format?!?)
validate(input("Would you like to me to deal you a card? \n"))