from time import clock class LinkedListNode: def __init__(self, inData, inNext): """Construct a new Linked List Node""" self.data = inData self.next = inNext def GetNextNode(self): return self.next def GetData(self): return self.data class LinkedList: def __init__(self,max): """Construct a new LinkedList. The first node and last node are the same. Size is 0""" self.firstNode = LinkedListNode(None, None) self.lastNode = self.firstNode self.size = 0 self.maxsize=max def Add(self, data): """Add a node to the list""" node = LinkedListNode(data, None) node.data = data; if self.size<=self.maxsize: if self.firstNode.data == None: self.firstNode = node self.lastNode = node else: self.lastNode.next = node self.lastNode = node self.size += 1 else: print "List is Overflowed" def Remove(self): if self.size>0: self.firstNode=self.firstNode.next self.size=self.size-1 else: print "UnderFlowed" def Add_many(self, list_of_data): """Add a list of nodes to the linked list""" for x in list_of_data: self.add(x) def GetLength(self): return self.size def Traverse(self): list=[] tnode=self.firstNode while tnode!=None: list.append(str(tnode.GetData())) tnode=tnode.GetNextNode() return list def Front(self): return self.firstNode def Rear(self): return self.lastNode try: input=open('in9_10.txt','r+') output=open('out_33_9_10.txt','w') except IOError: print "The file does not exist" count=0 list2=[] list3=[] list4=[] operation=0 for row in input: if count==0: list=row.split(",") elif count>=2 and count<=5: list1=row.split(",") for i in range(len(list1)): if list1[i]=="\n": pass else: list2.append(int(list1[i])) elif count>=7 and count<=9: list1=row.split(",") for i in range(len(list1)): if list1[i]=="\n": pass else: list4.append(int(list1[i])) else: pass count=count+1 start=clock() queue=LinkedList(int(list[0])) for i in list2: operation=operation+1 queue.Add(int(i)) for i in list4: queue.Add(int(i)) queue.Remove() operation=operation+2 output.write("Time Consumed is: "+str(clock()-start)+"\n") output.write("Size of the queue is: "+str(queue.size)+"\n") output.write("Total No of Operations Are: "+str(operation)+"\n") list3=queue.Traverse() count=1 for i in list3: if count%25==0 or count==len(list3)+1: output.write(i+"\n") else: output.write(i+",") count=count+1 output.close()