mypytool 0.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mypytool-0.1.1/PKG-INFO +7 -0
- mypytool-0.1.1/README.md +0 -0
- mypytool-0.1.1/mypytool/__init__.py +15 -0
- mypytool-0.1.1/mypytool/date.py +21 -0
- mypytool-0.1.1/mypytool/graphic.py +104 -0
- mypytool-0.1.1/mypytool/linked_list.py +181 -0
- mypytool-0.1.1/mypytool/queue.py +34 -0
- mypytool-0.1.1/mypytool/sort.py +183 -0
- mypytool-0.1.1/mypytool/stack.py +28 -0
- mypytool-0.1.1/mypytool.egg-info/PKG-INFO +7 -0
- mypytool-0.1.1/mypytool.egg-info/SOURCES.txt +14 -0
- mypytool-0.1.1/mypytool.egg-info/dependency_links.txt +1 -0
- mypytool-0.1.1/mypytool.egg-info/requires.txt +1 -0
- mypytool-0.1.1/mypytool.egg-info/top_level.txt +1 -0
- mypytool-0.1.1/pyproject.toml +9 -0
- mypytool-0.1.1/setup.cfg +4 -0
mypytool-0.1.1/PKG-INFO
ADDED
mypytool-0.1.1/README.md
ADDED
|
File without changes
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
__version__ = "0.1.1"
|
|
2
|
+
__author__ = "Tutu"
|
|
3
|
+
__name__ = "mypytool"
|
|
4
|
+
|
|
5
|
+
from .graphic import *
|
|
6
|
+
from .sort import *
|
|
7
|
+
from .date import *
|
|
8
|
+
from .queue import *
|
|
9
|
+
from .stack import *
|
|
10
|
+
from .main import *
|
|
11
|
+
from .linked_list import *
|
|
12
|
+
|
|
13
|
+
# __all__ = ["graphic", "sort", "date", "queue", "stack", "main", "linked_list"]
|
|
14
|
+
|
|
15
|
+
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
def month_first_day(day,week):
|
|
2
|
+
day %= 7
|
|
3
|
+
if day == 0:
|
|
4
|
+
day=7
|
|
5
|
+
return week - (day - 1)
|
|
6
|
+
|
|
7
|
+
def leap_year(y):
|
|
8
|
+
if (y % 400 == 0) or (y % 4 == 0 and y % 100 != 0):
|
|
9
|
+
return True
|
|
10
|
+
return False
|
|
11
|
+
|
|
12
|
+
def month_day(y = 2026, m=1):
|
|
13
|
+
if m == 2:
|
|
14
|
+
if leap_year(y):
|
|
15
|
+
return 29
|
|
16
|
+
else:
|
|
17
|
+
return 28
|
|
18
|
+
elif m == 1 or m == 3 or m == 5 or m == 7 or m == 8 or m == 10 or m == 12:
|
|
19
|
+
return 31
|
|
20
|
+
else:
|
|
21
|
+
return 30
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import math
|
|
2
|
+
from . import main
|
|
3
|
+
class Circle():
|
|
4
|
+
def __init__(self,radius):
|
|
5
|
+
self.Radius = radius
|
|
6
|
+
self.Area = math.pi * (main.pow(self.Radius,2))
|
|
7
|
+
self.Perimeter = math.pi * (2 * self.Radius)
|
|
8
|
+
def radius(self):
|
|
9
|
+
return self.Radius
|
|
10
|
+
def area(self):
|
|
11
|
+
return self.Area
|
|
12
|
+
def perimeter(self):
|
|
13
|
+
return self.Perimeter
|
|
14
|
+
|
|
15
|
+
class Square():
|
|
16
|
+
def __init__(self,side_length):
|
|
17
|
+
self.Side_length = side_length
|
|
18
|
+
self.Perimeter = 4 * side_length
|
|
19
|
+
self.Area = side_length * side_length
|
|
20
|
+
def side_length(self):
|
|
21
|
+
return self.Side_length
|
|
22
|
+
def area(self):
|
|
23
|
+
return self.Area
|
|
24
|
+
def perimeter(self):
|
|
25
|
+
return self.Perimeter
|
|
26
|
+
|
|
27
|
+
class Rectangle():
|
|
28
|
+
def __init__(self,Length, Width):
|
|
29
|
+
self.Length = Length
|
|
30
|
+
self.Width = Width
|
|
31
|
+
self.Perimeter = (self.Length + self.Width) * 2
|
|
32
|
+
self.Area = self.Length * self.Width
|
|
33
|
+
def width(self):
|
|
34
|
+
return self.Width
|
|
35
|
+
def length(self):
|
|
36
|
+
return self.Length
|
|
37
|
+
def area(self):
|
|
38
|
+
return self.Area
|
|
39
|
+
def perimeter(self):
|
|
40
|
+
return self.Perimeter
|
|
41
|
+
|
|
42
|
+
class Triangle():
|
|
43
|
+
def __init__(self,a,h,b,c):
|
|
44
|
+
self.a = a
|
|
45
|
+
self.b = b
|
|
46
|
+
self.c = c
|
|
47
|
+
self.h = h
|
|
48
|
+
self.Area = a * h / 2
|
|
49
|
+
self.Perimeter = a + b + c
|
|
50
|
+
def alen(self):
|
|
51
|
+
return self.a
|
|
52
|
+
def blen(self):
|
|
53
|
+
return self.b
|
|
54
|
+
def clen(self):
|
|
55
|
+
return self.c
|
|
56
|
+
def high(self):
|
|
57
|
+
return self.h
|
|
58
|
+
def area(self):
|
|
59
|
+
return self.Area
|
|
60
|
+
def perimeter(self):
|
|
61
|
+
return self.Perimeter
|
|
62
|
+
|
|
63
|
+
class Parallelogram():
|
|
64
|
+
def __init__(self,a,b,h):
|
|
65
|
+
self.a = a
|
|
66
|
+
self.b = b
|
|
67
|
+
self.h = h
|
|
68
|
+
self.Area = a * h
|
|
69
|
+
self.Perimeter = a*2 + b*2
|
|
70
|
+
def alen(self):
|
|
71
|
+
return self.a
|
|
72
|
+
def blen(self):
|
|
73
|
+
return self.b
|
|
74
|
+
def hlen(self):
|
|
75
|
+
return self.h
|
|
76
|
+
def area(self):
|
|
77
|
+
return self.Area
|
|
78
|
+
def perimeter(self):
|
|
79
|
+
return self.Perimeter
|
|
80
|
+
|
|
81
|
+
class Trapezoid():
|
|
82
|
+
def __init__(self,a,b,h,c,d):
|
|
83
|
+
self.a = a
|
|
84
|
+
self.b = b
|
|
85
|
+
self.h = h
|
|
86
|
+
self.c = c
|
|
87
|
+
self.d = d
|
|
88
|
+
self.Area = (a + b) * h / 2
|
|
89
|
+
self.Perimeter = a + b + c + d
|
|
90
|
+
def alen(self):
|
|
91
|
+
return self.a
|
|
92
|
+
def blen(self):
|
|
93
|
+
return self.b
|
|
94
|
+
def hlen(self):
|
|
95
|
+
return self.h
|
|
96
|
+
def clen(self):
|
|
97
|
+
return self.c
|
|
98
|
+
def dblen(self):
|
|
99
|
+
return self.d
|
|
100
|
+
def area(self):
|
|
101
|
+
return self.Area
|
|
102
|
+
def perimeter(self):
|
|
103
|
+
return self.Perimeter
|
|
104
|
+
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
class Linked_node:
|
|
2
|
+
def __init__(self,list,point=None,id=0):
|
|
3
|
+
self.n = list
|
|
4
|
+
self.points = point
|
|
5
|
+
self.id = id
|
|
6
|
+
class General_Linked_list:
|
|
7
|
+
def __init__(self,n=None):
|
|
8
|
+
self.head = Linked_node(n)
|
|
9
|
+
self.element = 1
|
|
10
|
+
def append(self,n):
|
|
11
|
+
new_Linkednode = Linked_node(n,None,self.element)
|
|
12
|
+
temp = self.head
|
|
13
|
+
for i in range(self.element - 1):
|
|
14
|
+
temp = self.head.points
|
|
15
|
+
temp.points = new_Linkednode
|
|
16
|
+
self.element += 1
|
|
17
|
+
def display(self):
|
|
18
|
+
temp = self.head
|
|
19
|
+
for i in range(self.element):
|
|
20
|
+
print(temp.n,end=" -> ")
|
|
21
|
+
temp = temp.points
|
|
22
|
+
def delet(self):
|
|
23
|
+
self.element -= 1
|
|
24
|
+
temp = self.head
|
|
25
|
+
for i in range(self.element - 1):
|
|
26
|
+
temp = self.head.points
|
|
27
|
+
temp.points = None
|
|
28
|
+
def is_empty(self):
|
|
29
|
+
return self.head is None
|
|
30
|
+
def length(self):
|
|
31
|
+
return self.element
|
|
32
|
+
def items(self):
|
|
33
|
+
temp = self.head
|
|
34
|
+
while temp is not None:
|
|
35
|
+
yield temp.n
|
|
36
|
+
temp = temp.points
|
|
37
|
+
def add(self,n,place=1):
|
|
38
|
+
temp = self.head
|
|
39
|
+
temp2 = Linked_node(n,temp.points,place)
|
|
40
|
+
if self.is_empty():
|
|
41
|
+
self.head.points = temp2
|
|
42
|
+
elif place > (self.length() - 1):
|
|
43
|
+
self.append(n)
|
|
44
|
+
else:
|
|
45
|
+
for i in range(place - 1):
|
|
46
|
+
temp = temp.points
|
|
47
|
+
temp2.points = temp.points
|
|
48
|
+
temp.points = temp2
|
|
49
|
+
temp2.points.id += 1
|
|
50
|
+
self.element += 1
|
|
51
|
+
def insert(self,n,place=1):
|
|
52
|
+
temp = self.head
|
|
53
|
+
temp2 = Linked_node(n,temp.points,place)
|
|
54
|
+
if self.is_empty():
|
|
55
|
+
self.head.points = temp2
|
|
56
|
+
elif place > (self.length() - 1):
|
|
57
|
+
self.append(n)
|
|
58
|
+
else:
|
|
59
|
+
for i in range(place - 1):
|
|
60
|
+
temp = temp.points
|
|
61
|
+
temp2.points = temp.points
|
|
62
|
+
temp.points = temp2
|
|
63
|
+
temp2.points.id += 1
|
|
64
|
+
self.element += 1
|
|
65
|
+
def remove(self,place=1):
|
|
66
|
+
temp = self.head
|
|
67
|
+
if not self.is_empty:
|
|
68
|
+
if place > (self.length() - 1):
|
|
69
|
+
self.delet()
|
|
70
|
+
else:
|
|
71
|
+
for i in range(place - 1):
|
|
72
|
+
temp = temp.points
|
|
73
|
+
temp2 = temp.points
|
|
74
|
+
temp2.point.id -= 1
|
|
75
|
+
temp.points = temp2.points
|
|
76
|
+
self.element -= 1
|
|
77
|
+
def find(self,n):
|
|
78
|
+
return n in self.items()
|
|
79
|
+
class Cycle_Linked_list:
|
|
80
|
+
def __init__(self,n=None):
|
|
81
|
+
self.head = Linked_node(n)
|
|
82
|
+
self.element = 1
|
|
83
|
+
def append(self,n):
|
|
84
|
+
temp = Linked_node(n,id=self.element)
|
|
85
|
+
temp.points = temp
|
|
86
|
+
if self.element == 1:
|
|
87
|
+
self.head.points = temp
|
|
88
|
+
else:
|
|
89
|
+
temp2 = self.head
|
|
90
|
+
for i in range(self.element - 1):
|
|
91
|
+
temp2 = temp2.points
|
|
92
|
+
temp.points = self.head.points
|
|
93
|
+
temp2.points = temp
|
|
94
|
+
self.element += 1
|
|
95
|
+
def delet(self):
|
|
96
|
+
temp = self.head
|
|
97
|
+
self.element -= 1
|
|
98
|
+
for i in range(self.element - 1):
|
|
99
|
+
temp = temp.points
|
|
100
|
+
if self.element == 1:
|
|
101
|
+
self.head.points = None
|
|
102
|
+
else:
|
|
103
|
+
temp.points = self.head.points
|
|
104
|
+
def items(self):
|
|
105
|
+
temp = self.head
|
|
106
|
+
for i in range(self.element):
|
|
107
|
+
yield temp.n
|
|
108
|
+
temp = temp.points
|
|
109
|
+
def display(self):
|
|
110
|
+
temp = self.head
|
|
111
|
+
for i in range(self.element):
|
|
112
|
+
print(temp.n,end=" -> ")
|
|
113
|
+
temp = temp.points
|
|
114
|
+
def is_empty(self):
|
|
115
|
+
return self.head.points is None
|
|
116
|
+
def length(self):
|
|
117
|
+
return self.element
|
|
118
|
+
def add(self,n,place=1):
|
|
119
|
+
temp = self.head
|
|
120
|
+
temp2 = Linked_node(n,id=place)
|
|
121
|
+
temp2.points = temp2
|
|
122
|
+
if self.is_empty():
|
|
123
|
+
self.head.points = temp2
|
|
124
|
+
elif place == 1:
|
|
125
|
+
temp2.points = temp.points
|
|
126
|
+
self.head.points = temp2
|
|
127
|
+
temp3 = self.head
|
|
128
|
+
for i in range(self.element - 1):
|
|
129
|
+
temp3 = temp3.points
|
|
130
|
+
temp3.points = temp2
|
|
131
|
+
elif place > (self.length() - 1):
|
|
132
|
+
self.append(n)
|
|
133
|
+
else:
|
|
134
|
+
for i in range(place - 1):
|
|
135
|
+
temp = temp.points
|
|
136
|
+
temp2.points = temp.points
|
|
137
|
+
temp.points = temp2
|
|
138
|
+
self.element += 1
|
|
139
|
+
def insert(self,n,place=1):
|
|
140
|
+
temp = self.head
|
|
141
|
+
temp2 = Linked_node(n,id=place)
|
|
142
|
+
temp2.points = temp2
|
|
143
|
+
if self.is_empty():
|
|
144
|
+
self.head.points = temp2
|
|
145
|
+
elif place == 1:
|
|
146
|
+
temp2.points = temp.points
|
|
147
|
+
self.head.points = temp2
|
|
148
|
+
temp3 = self.head
|
|
149
|
+
for i in range(self.element):
|
|
150
|
+
temp3 = temp3.points
|
|
151
|
+
temp3.points = temp2
|
|
152
|
+
elif place > (self.length() - 1):
|
|
153
|
+
self.append(n)
|
|
154
|
+
else:
|
|
155
|
+
for i in range(place - 1):
|
|
156
|
+
temp = temp.points
|
|
157
|
+
temp2.points = temp.points
|
|
158
|
+
temp.points = temp2
|
|
159
|
+
self.element += 1
|
|
160
|
+
def remove(self,place = 1):
|
|
161
|
+
temp = self.head
|
|
162
|
+
temp2 = self.head
|
|
163
|
+
if not self.is_empty():
|
|
164
|
+
if not self.length == 2:
|
|
165
|
+
if place > (self.length() - 1):
|
|
166
|
+
self.delet()
|
|
167
|
+
elif place == 1:
|
|
168
|
+
temp.points = temp.points.points
|
|
169
|
+
for i in range(self.element - 1):
|
|
170
|
+
temp2 = temp2.points
|
|
171
|
+
temp2.points = self.head.points
|
|
172
|
+
|
|
173
|
+
else:
|
|
174
|
+
for i in range(place - 2):
|
|
175
|
+
temp = temp.points
|
|
176
|
+
temp.points = temp.points.points
|
|
177
|
+
else:
|
|
178
|
+
self.head.points = None
|
|
179
|
+
self.element -= 1
|
|
180
|
+
def find(self,n):
|
|
181
|
+
return n in self.items()
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
class Queue():
|
|
2
|
+
def __init__(self,Front=0,End = 0):
|
|
3
|
+
self.Front = Front
|
|
4
|
+
self.End = End
|
|
5
|
+
self.endcp = End
|
|
6
|
+
self.queue = [0]
|
|
7
|
+
if self.End != 0 or self.Front != 0:
|
|
8
|
+
for i in range(self.End + self.Front):
|
|
9
|
+
self.queue.append(0)
|
|
10
|
+
def push(self,n):
|
|
11
|
+
if self.End == self.endcp:
|
|
12
|
+
self.queue[self.End] = n
|
|
13
|
+
else:
|
|
14
|
+
self.queue.append(n)
|
|
15
|
+
self.End += 1
|
|
16
|
+
return None
|
|
17
|
+
def pop(self):
|
|
18
|
+
self.queue[self.Front] = 0
|
|
19
|
+
self.Front += 1
|
|
20
|
+
if self.End - self.Front == 0:
|
|
21
|
+
self.End = 0
|
|
22
|
+
self.Front = 0
|
|
23
|
+
return None
|
|
24
|
+
def size(self):
|
|
25
|
+
return self.End - self.Front
|
|
26
|
+
def empty(self):
|
|
27
|
+
if self.End - self.Front == 0:
|
|
28
|
+
return True
|
|
29
|
+
else:
|
|
30
|
+
return False
|
|
31
|
+
def front(self):
|
|
32
|
+
return self.queue[self.Front]
|
|
33
|
+
def back(self):
|
|
34
|
+
return self.queue[self.End]
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
def bubble_sort(arr, reverse = False):
|
|
2
|
+
if reverse:
|
|
3
|
+
l = len(arr)
|
|
4
|
+
for i in range(l):
|
|
5
|
+
for j in range(l - i - 1):
|
|
6
|
+
if arr[j] < arr[j + 1]:
|
|
7
|
+
t = arr[j]
|
|
8
|
+
arr[j] = arr[j+1]
|
|
9
|
+
arr[j+1] = t
|
|
10
|
+
return arr
|
|
11
|
+
else:
|
|
12
|
+
l = len(arr)
|
|
13
|
+
for i in range(l):
|
|
14
|
+
for j in range(0,l-i-1):
|
|
15
|
+
if arr[j] > arr[j+1]:
|
|
16
|
+
t = arr[j]
|
|
17
|
+
arr[j] = arr[j+1]
|
|
18
|
+
arr[j+1] = t
|
|
19
|
+
return arr
|
|
20
|
+
|
|
21
|
+
def bucket_sort(arr, reverse = False):
|
|
22
|
+
# breakpoint()
|
|
23
|
+
m_max = arr[0]
|
|
24
|
+
arr1 = []
|
|
25
|
+
out = []
|
|
26
|
+
mem = -1
|
|
27
|
+
for i in arr:
|
|
28
|
+
if(i > m_max):
|
|
29
|
+
m_max = i
|
|
30
|
+
for i in range(m_max + 1):
|
|
31
|
+
arr1.append(0)
|
|
32
|
+
for i in arr:
|
|
33
|
+
arr1[i] += 1
|
|
34
|
+
if reverse:
|
|
35
|
+
for i in range(len(arr1)):
|
|
36
|
+
ins = len(arr1) - i - 1
|
|
37
|
+
for j in range(arr1[ins]):
|
|
38
|
+
out.append(ins)
|
|
39
|
+
return out
|
|
40
|
+
else:
|
|
41
|
+
for i in arr1:
|
|
42
|
+
mem += 1
|
|
43
|
+
if i != 0:
|
|
44
|
+
for j in range(i):
|
|
45
|
+
out.append(mem)
|
|
46
|
+
return out
|
|
47
|
+
|
|
48
|
+
def selection_sort(arr, reverse = False):
|
|
49
|
+
if reverse:
|
|
50
|
+
for i in range(len(arr) - 1):
|
|
51
|
+
m_min = arr[i]
|
|
52
|
+
m_min_i = 0
|
|
53
|
+
for j in range(i,len(arr)):
|
|
54
|
+
if(arr[j] >= m_min):
|
|
55
|
+
m_min = arr[j]
|
|
56
|
+
m_min_i = j
|
|
57
|
+
arr[i] , arr[m_min_i] = arr[m_min_i] , arr[i]
|
|
58
|
+
return arr
|
|
59
|
+
else:
|
|
60
|
+
for i in range(len(arr) - 1):
|
|
61
|
+
m_min = arr[i]
|
|
62
|
+
m_min_i = 0
|
|
63
|
+
for j in range(i,len(arr)):
|
|
64
|
+
if(arr[j] <= m_min):
|
|
65
|
+
m_min = arr[j]
|
|
66
|
+
m_min_i = j
|
|
67
|
+
arr[i] , arr[m_min_i] = arr[m_min_i] , arr[i]
|
|
68
|
+
return arr
|
|
69
|
+
|
|
70
|
+
def insertion_sort(arr, reverse = False):
|
|
71
|
+
if reverse:
|
|
72
|
+
n = len(arr)
|
|
73
|
+
for i in range(1,n):
|
|
74
|
+
k = arr[i]
|
|
75
|
+
j = i - 1
|
|
76
|
+
while j >= 0 and k > arr[j]:
|
|
77
|
+
arr[j + 1] = arr[j]
|
|
78
|
+
j -= 1
|
|
79
|
+
arr[j + 1] = k
|
|
80
|
+
return arr
|
|
81
|
+
else:
|
|
82
|
+
n = len(arr)
|
|
83
|
+
for i in range(1,n):
|
|
84
|
+
k = arr[i]
|
|
85
|
+
j = i - 1
|
|
86
|
+
while j >= 0 and k < arr[j]:
|
|
87
|
+
arr[j + 1] = arr[j]
|
|
88
|
+
j -= 1
|
|
89
|
+
arr[j + 1] = k
|
|
90
|
+
return arr
|
|
91
|
+
|
|
92
|
+
def shell_sort(arr, reverse = False):
|
|
93
|
+
if reverse:
|
|
94
|
+
n = len(arr)
|
|
95
|
+
len_t = n // 2
|
|
96
|
+
while len_t > 0:
|
|
97
|
+
for i in range(len_t, n):
|
|
98
|
+
temp = arr[i]
|
|
99
|
+
j = i
|
|
100
|
+
while j >= len_t and arr[j - len_t] < temp:
|
|
101
|
+
arr[j] = arr[j - len_t]
|
|
102
|
+
j -= len_t
|
|
103
|
+
arr[j] = temp
|
|
104
|
+
len_t //= 2
|
|
105
|
+
return arr
|
|
106
|
+
else:
|
|
107
|
+
n = len(arr)
|
|
108
|
+
len_t = n // 2
|
|
109
|
+
while len_t > 0:
|
|
110
|
+
for i in range(len_t, n):
|
|
111
|
+
temp = arr[i]
|
|
112
|
+
j = i
|
|
113
|
+
while j >= len_t and arr[j - len_t] > temp:
|
|
114
|
+
arr[j] = arr[j - len_t]
|
|
115
|
+
j -= len_t
|
|
116
|
+
arr[j] = temp
|
|
117
|
+
len_t //= 2
|
|
118
|
+
return arr
|
|
119
|
+
|
|
120
|
+
def merge_sort(arr, reverse = False):
|
|
121
|
+
out = merge_sortt(arr)
|
|
122
|
+
if reverse:
|
|
123
|
+
return out.reverse()
|
|
124
|
+
else:
|
|
125
|
+
return out
|
|
126
|
+
|
|
127
|
+
def merge_sortt(arr):
|
|
128
|
+
if len(arr) <= 1:
|
|
129
|
+
return arr
|
|
130
|
+
mid = len(arr) // 2
|
|
131
|
+
left_half = merge_sortt(arr[:mid])
|
|
132
|
+
right_half = merge_sortt(arr[mid:])
|
|
133
|
+
return merge(left_half, right_half)
|
|
134
|
+
|
|
135
|
+
def merge(left, right):
|
|
136
|
+
sorted_arr = []
|
|
137
|
+
i = j = 0
|
|
138
|
+
while i < len(left) and j < len(right):
|
|
139
|
+
if left[i] < right[j]:
|
|
140
|
+
sorted_arr.append(left[i])
|
|
141
|
+
i += 1
|
|
142
|
+
else:
|
|
143
|
+
sorted_arr.append(right[j])
|
|
144
|
+
j += 1
|
|
145
|
+
sorted_arr.extend(left[i:])
|
|
146
|
+
sorted_arr.extend(right[j:])
|
|
147
|
+
return sorted_arr
|
|
148
|
+
|
|
149
|
+
def quick_sort(arr, reverse = False):
|
|
150
|
+
if len(arr) <= 1:
|
|
151
|
+
return arr
|
|
152
|
+
right = len(arr)
|
|
153
|
+
std = arr[0]
|
|
154
|
+
leftl = []
|
|
155
|
+
rightl = []
|
|
156
|
+
time = 0
|
|
157
|
+
for i in arr:
|
|
158
|
+
if time == 0:
|
|
159
|
+
time += 1
|
|
160
|
+
continue
|
|
161
|
+
if i <= std:
|
|
162
|
+
leftl.append(i)
|
|
163
|
+
if i > std:
|
|
164
|
+
rightl.append(i)
|
|
165
|
+
time += 1
|
|
166
|
+
if reverse:
|
|
167
|
+
return quick_sort(rightl,True) + [std] + quick_sort(leftl,True)
|
|
168
|
+
else:
|
|
169
|
+
return quick_sort(leftl) + [std] + quick_sort(rightl)
|
|
170
|
+
|
|
171
|
+
def ascending_order(arr, sorting_algorithm):
|
|
172
|
+
out = sorting_algorithm(arr)
|
|
173
|
+
return out
|
|
174
|
+
|
|
175
|
+
def descending_order(arr, sorting_algorithm):
|
|
176
|
+
out = sorting_algorithm(arr,True)
|
|
177
|
+
return out
|
|
178
|
+
|
|
179
|
+
def sort(arr, sorting_algorithm = quick_sort, sort_order = ascending_order, reverse = None):
|
|
180
|
+
if reverse != None:
|
|
181
|
+
return sorting_algorithm(arr,reverse)
|
|
182
|
+
out = sort_order(arr, sorting_algorithm)
|
|
183
|
+
return out
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
class Stack():
|
|
2
|
+
def __init__(self,Top = 0):
|
|
3
|
+
self.Top = Top
|
|
4
|
+
self.Bottom = Top
|
|
5
|
+
self.stack = [0]
|
|
6
|
+
|
|
7
|
+
def top(self):
|
|
8
|
+
return self.stack[self.Top - 1]
|
|
9
|
+
def push(self,n):
|
|
10
|
+
if self.Top == 0:
|
|
11
|
+
self.stack[self.Top] = n
|
|
12
|
+
else:
|
|
13
|
+
self.stack.append(n)
|
|
14
|
+
self.Top+=1
|
|
15
|
+
return None
|
|
16
|
+
def pop(self):
|
|
17
|
+
self.Top -= 1
|
|
18
|
+
self.stack[self.Top] = 0
|
|
19
|
+
if self.Top - self.Bottom == 0:
|
|
20
|
+
self.Top = self.Bottom
|
|
21
|
+
return None
|
|
22
|
+
def empty(self):
|
|
23
|
+
if self.Top - self.Bottom == 0:
|
|
24
|
+
return True
|
|
25
|
+
else:
|
|
26
|
+
return False
|
|
27
|
+
def size(self):
|
|
28
|
+
return self.Top - self.Bottom
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
mypytool/__init__.py
|
|
4
|
+
mypytool/date.py
|
|
5
|
+
mypytool/graphic.py
|
|
6
|
+
mypytool/linked_list.py
|
|
7
|
+
mypytool/queue.py
|
|
8
|
+
mypytool/sort.py
|
|
9
|
+
mypytool/stack.py
|
|
10
|
+
mypytool.egg-info/PKG-INFO
|
|
11
|
+
mypytool.egg-info/SOURCES.txt
|
|
12
|
+
mypytool.egg-info/dependency_links.txt
|
|
13
|
+
mypytool.egg-info/requires.txt
|
|
14
|
+
mypytool.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
tqdm>=4.67.1
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
mypytool
|
mypytool-0.1.1/setup.cfg
ADDED