This repository was archived by the owner on Apr 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueue.py
More file actions
59 lines (39 loc) · 1.36 KB
/
Queue.py
File metadata and controls
59 lines (39 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
class Queue():
def __init__(self,name):
self.data = list()
self.name = name
def add(self,index,value):
self.data.insert(index,value)
return (0,"Succcess")
def remove(self,index):
if 0<index or index >= len(self.data):
return (1,"Index out of range")
else:
del(self.data[index])
return (0,"Success")
def changeName(self,newName):
if newName == "":
return (1,"Name can't be empty")
self.name = newName
return (0,"Success")
def removeMult(self,l):
for index in l:
if 0 < index or index >= len(self.data):
return (1, "Index out of range, No action has been done.")
for index in l:
del(self.data[index])
return (0,"Success")
def switch(self,index1,index2):
if 0<index1 or index1 >= len(self.data):
return (1,"Index1 out of range")
if 0<index2 or index2 >= len(self.data):
return (1,"Index2 out of range")
tmp = self.data[index1]
self.data[index1] = self.data[index2]
self.data[index2] = tmp
return (0,"Success")
def DATA(self):
result = {"name": self.name, "data" : {}}
for index in range(0,len(self.data)):
result["data"][index] = self.data[index]
return result