-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutility.py
More file actions
57 lines (47 loc) · 1.28 KB
/
utility.py
File metadata and controls
57 lines (47 loc) · 1.28 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
55
56
57
import os
import numpy as np
from collections import deque
class Queue:
def __init__(self):
self.dq = deque([])
self.sz = 0
def push(self, x):
self.dq.append(x)
self.sz+=1
def pop(self):
if(self.sz==0): return
self.dq.popleft()
self.sz-=1
def empty(self):
if(self.sz==0): return True
return False
def front(self):
if(self.sz==0): return -1
x = self.dq.popleft()
self.dq.appendleft(x)
return x
def rear(self):
if(self.sz==0): return -1
x = self.dq.pop()
self.dq.append(x)
return x
def copy_queue(self, queue):
while(not queue.empty()):
self.push(queue.front())
queue.pop()
return
def calculate_dist(a, b):
return np.sqrt(np.square(a[0]-b[0])+np.square(a[1]-b[1]))
def create_directory(directory_name):
try:
os.mkdir(directory_name)
print(f"Create {directory_name} successfully.")
except FileExistsError:
print(f"{directory_name} existed.\n")
return
except PermissionError:
print(f"Creating {directory_name} denied.")
return
except Exception as e:
print(f"Creating {directory_name} error.")
return