1.

Write Insert (city) and Delete (City) methods in Python to add City and Remove City considering them to act as Insert and Delete operations of the data structure Queue.

Answer»

class queue:

city=[ ]

def Insert (self):

a = raw_input(“Enter city”)

queue.city append (a)

def Delete (self):

if (queue, city = = []):

print “Queue empty”

else:

print “Deleted element is”,

queue.city[0]

queue.city.delete ()

OR

class queue:

city=[ ]

def Insert(self):

a=raw_input(“Enter city”)

queue.a.append(a)

def Delete(self):

if (queue.city==[ ]):

print (“Queue emtpy”)

else

print (“Deleted element is”,queue, city [0])



Discussion

No Comment Found