Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit429b3de

Browse files
author
shengshijun
committed
reformat代码
1 parent56efd99 commit429b3de

File tree

56 files changed

+123
-208
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+123
-208
lines changed

‎src/clrs/9/9-2(b).py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ def partition(li, start, end):
1414
li_len=end-start+1
1515
ifli_len<2:
1616
raiseValueError("list which lenght is less then 2 do not need to partition")
17-
#使用随机元素元素作为分割点并且把随机元素放在列表最后
18-
#这样就可以不变动原来的逻辑了
17+
#使用随机元素元素作为分割点并且把随机元素放在列表最后
18+
#这样就可以不变动原来的逻辑了
1919
key_index=randint(start,end)
2020
key=li[key_index]
2121
li[key_index],li[end]=li[end],li[key_index]

‎src/clrs/9/9-2(c).py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ def partition(li, start, end):
77
li_len=end-start+1
88
ifli_len<2:
99
raiseValueError("list which lenght is less then 2 do not need to partition")
10-
#使用随机元素元素作为分割点并且把随机元素放在列表最后
11-
#这样就可以不变动原来的逻辑了
10+
#使用随机元素元素作为分割点并且把随机元素放在列表最后
11+
#这样就可以不变动原来的逻辑了
1212
key_index=randint(start,end)
1313
key=li[key_index]
1414
li[key_index],li[end]=li[end],li[key_index]
@@ -27,7 +27,7 @@ def partition(li, start, end):
2727

2828

2929
defselection(li,start,end,kth):
30-
#一定会找到一个元素,因此这儿直接返回是对的。
30+
#一定会找到一个元素,因此这儿直接返回是对的。
3131
ifstart==end:
3232
returnstart
3333
mid_index=partition(li,start,end)
@@ -88,4 +88,3 @@ def main():
8888

8989
if__name__=='__main__':
9090
main()
91-

‎src/divide_conquer/find_max_sublist.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def find_max_sublist(li):
3939
deffind_max_in_middle(li,middle):
4040
li_len=len(li)
4141
left_max_index,right_max_index=0,middle
42-
#这里有一个bug,如果列表里面所有的数据都是负的,那么就找不到最小值了
42+
#这里有一个bug,如果列表里面所有的数据都是负的,那么就找不到最小值了
4343
left_max_sum,cur_sum,right_max_sum=li[middle-1],0,li[middle]
4444
forxinreversed(xrange(0,middle)):
4545
cur_sum+=li[x]
@@ -52,7 +52,7 @@ def find_max_in_middle(li, middle):
5252
ifcur_sum>right_max_sum:
5353
right_max_sum=cur_sum
5454
right_max_index=x
55-
#这里并没有判断一端结果为负的情况,因为这个时候可以在其中一端的列表中得到最大子数列
55+
#这里并没有判断一端结果为负的情况,因为这个时候可以在其中一端的列表中得到最大子数列
5656
return (left_max_index,right_max_index,right_max_sum+left_max_sum)
5757

5858

@@ -61,4 +61,4 @@ def main():
6161

6262

6363
if__name__=='__main__':
64-
main()
64+
main()

‎src/divide_conquer/find_max_sublist_without_ recursion.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ def find_max_sublist(li):
1313
right=x
1414
max_sum=b
1515

16-
return(left,right,max_sum)
16+
returnleft,right,max_sum
1717

1818

1919
defmain():
2020
printfind_max_sublist([1,-2,3,10,-4,7,2,-5])
2121

2222

2323
if__name__=='__main__':
24-
main()
24+
main()

‎src/divide_conquer/power.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ def main():
1717

1818

1919
if__name__=='__main__':
20-
main()
20+
main()

‎src/divide_conquer/yong_matrix.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def extract_min(matrix, w, h):
1313
left=empty_index+w
1414
right=empty_index+1
1515
# 1,矩阵碰到右边界的时候
16-
#2,右边的值是None,表示没有元素
16+
#2,右边的值是None,表示没有元素
1717
print"left :",left
1818
print"right :",right
1919
ifleft> (w*h-1)andright%wis0:
@@ -23,12 +23,12 @@ def extract_min(matrix, w, h):
2323
ifleft<= (w*h-1)and (right%wis0ormatrix[right]isNoneormatrix[left]<=matrix[right]):
2424
matrix[empty_index]=matrix[left]
2525
empty_index=left
26-
#1,判断矩阵碰到左边界的时候
27-
#2,左边的值是None,表示值是None
26+
#1,判断矩阵碰到左边界的时候
27+
#2,左边的值是None,表示值是None
2828
elifleft> (w*h-1)ormatrix[left]isNoneormatrix[left]>matrix[right]:
2929
matrix[empty_index]=matrix[right]
3030
empty_index=right
31-
#到最终节点的时候
31+
#到最终节点的时候
3232
else:
3333
matrix[empty_index]=None
3434
break
@@ -47,4 +47,3 @@ def main():
4747

4848
if__name__=='__main__':
4949
main()
50-

‎src/dynamic/fabo/fabo_loop.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
使用循环实现的斐波那契数列其实就是自底向上方式实现的动态规划
55
"""
66

7+
78
defloop_fibonacci(n):
89
this=0
910
next=1
@@ -25,4 +26,4 @@ def main():
2526

2627

2728
if__name__=='__main__':
28-
main()
29+
main()

‎src/dynamic/fabo/fabo_up_down.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ def main():
2424

2525

2626
if__name__=="__main__":
27-
main()
27+
main()

‎src/dynamic/lcs/down_up.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,4 @@ def main():
7070

7171

7272
if__name__=="__main__":
73-
main()
73+
main()

‎src/dynamic/lcs/up_down.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,4 @@ def main():
6767

6868

6969
if__name__=="__main__":
70-
main()
70+
main()

‎src/dynamic/lps/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
#!/usr/bin/env python
22
# -*- coding:UTF-8
33
__author__='shenshijun'
4-
5-

‎src/dynamic/lps/down_up.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@ def main():
5050

5151

5252
if__name__=="__main__":
53-
main()
53+
main()

‎src/dynamic/lps/up_down.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,3 @@ def main():
5656

5757
if__name__=="__main__":
5858
main()
59-
60-

‎src/dynamic/task/max_weighted_action.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,3 @@ def main():
7979

8080
if__name__=="__main__":
8181
main()
82-

‎src/graph/general_graph.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -188,26 +188,3 @@ def main():
188188

189189
if__name__=="__main__":
190190
main()
191-
192-
193-
194-
195-
196-
197-
198-
199-
200-
201-
202-
203-
204-
205-
206-
207-
208-
209-
210-
211-
212-
213-

‎src/greedy/max_task_count.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,3 @@ def main():
2626

2727
if__name__=="__main__":
2828
main()
29-
30-

‎src/hashtable/HashMap.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,3 @@ def main():
154154

155155
if__name__=="__main__":
156156
main()
157-
158-
159-

‎src/hashtable/OpenAddressMap.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,3 @@ def main():
156156

157157
if__name__=="__main__":
158158
main()
159-

‎src/heap/max_heap.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ def heapify(self, parent):
3434
largest=parent
3535
left=parent*2+1
3636
right=parent*2+2
37-
#这个地方使用left和right比较,是为了防止到了叶节点的时候会出现数组越界。
37+
#这个地方使用left和right比较,是为了防止到了叶节点的时候会出现数组越界。
3838
ifleft<self.lengthandself.__array[parent]<self.__array[left]:
3939
largest=left
4040

4141
ifright<self.lengthandself.__array[largest]<self.__array[right]:
4242
largest=right
4343

44-
#保证在父元素就是最大值的时候不要移动元素
44+
#保证在父元素就是最大值的时候不要移动元素
4545
iflargest!=parent:
4646
self.__array[largest],self.__array[parent]=self.__array[parent],self.__array[largest]
4747
self.heapify(largest)
@@ -56,14 +56,14 @@ def loop_heapify(self, parent):
5656
largest=parent
5757
left=parent*2+1
5858
right=parent*2+2
59-
#这个地方使用left和right比较,是为了防止到了叶节点的时候会出现数组越界。
59+
#这个地方使用left和right比较,是为了防止到了叶节点的时候会出现数组越界。
6060
ifleft<self.lengthandself.__array[parent]<self.__array[left]:
6161
largest=left
6262

6363
ifright<self.lengthandself.__array[largest]<self.__array[right]:
6464
largest=right
6565

66-
#保证在父元素就是最大值的时候不要移动元素
66+
#保证在父元素就是最大值的时候不要移动元素
6767
iflargest!=parent:
6868
self.__array[largest],self.__array[parent]=self.__array[parent],self.__array[largest]
6969
parent=largest
@@ -88,7 +88,6 @@ def __deep_walk_through(self, func, start=0):
8888
self.__deep_walk_through(func,left)
8989
self.__deep_walk_through(func,right)
9090

91-
9291
def__str__(self):
9392
title="Heap Length: %s\n"%self.length
9493
content_list= [title]
@@ -116,4 +115,4 @@ def main():
116115

117116

118117
if__name__=='__main__':
119-
main()
118+
main()

‎src/heap/max_queue.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ def heapify(self, parent):
3131
largest=parent
3232
left=parent*2+1
3333
right=parent*2+2
34-
#这个地方使用left和right比较,是为了防止到了叶节点的时候会出现数组越界。
34+
#这个地方使用left和right比较,是为了防止到了叶节点的时候会出现数组越界。
3535
ifleft<self.lengthandself.__array[parent]<self.__array[left]:
3636
largest=left
3737

3838
ifright<self.lengthandself.__array[largest]<self.__array[right]:
3939
largest=right
4040

41-
#保证在父元素就是最大值的时候不要移动元素
41+
#保证在父元素就是最大值的时候不要移动元素
4242
iflargest!=parent:
4343
self.__array[largest],self.__array[parent]=self.__array[parent],self.__array[largest]
4444
self.heapify(largest)
@@ -52,14 +52,14 @@ def loop_heapify(self, parent):
5252
largest=parent
5353
left=parent*2+1
5454
right=parent*2+2
55-
#这个地方使用left和right比较,是为了防止到了叶节点的时候会出现数组越界。
55+
#这个地方使用left和right比较,是为了防止到了叶节点的时候会出现数组越界。
5656
ifleft<self.lengthandself.__array[parent]<self.__array[left]:
5757
largest=left
5858

5959
ifright<self.lengthandself.__array[largest]<self.__array[right]:
6060
largest=right
6161

62-
#保证在父元素就是最大值的时候不要移动元素
62+
#保证在父元素就是最大值的时候不要移动元素
6363
iflargest!=parent:
6464
self.__array[largest],self.__array[parent]=self.__array[parent],self.__array[largest]
6565
parent=largest
@@ -84,7 +84,6 @@ def __deep_walk_through(self, func, start=0):
8484
self.__deep_walk_through(func,left)
8585
self.__deep_walk_through(func,right)
8686

87-
8887
def__str__(self):
8988
title="Heap Length: %s\n"%self.length
9089
content_list= [title]
@@ -102,7 +101,7 @@ def append(self, value):
102101
insert_index=self.length
103102
whileTrue:
104103
parent= (insert_index-1)/2
105-
#这儿需要判断使得parent不会越界
104+
#这儿需要判断使得parent不会越界
106105
ifparent>=0andself.__array[insert_index]>self.__array[parent]:
107106
self.__array[parent],self.__array[insert_index]=self.__array[insert_index],self.__array[parent]
108107
insert_index=parent
@@ -119,7 +118,7 @@ def append_with_one_assign(self, value):
119118
insert_index=self.length
120119
whileTrue:
121120
parent= (insert_index-1)/2
122-
#这儿需要判断使得parent不会越界
121+
#这儿需要判断使得parent不会越界
123122
ifparent>=0andvalue>self.__array[parent]:
124123
self.__array[insert_index]=self.__array[parent]
125124
insert_index=parent
@@ -128,7 +127,6 @@ def append_with_one_assign(self, value):
128127
self.__array[insert_index]=value
129128
self.length+=1
130129

131-
132130
def__setitem__(self,index,value):
133131
self.__array[index]=value
134132

@@ -220,7 +218,6 @@ def __setitem__(self, key, value):
220218
node=MaxQueue.Node(key,value)
221219
self.__heap.append_with_one_assign(node)
222220

223-
224221
def__str__(self):
225222
returnstr(self.__heap)
226223

‎src/lib/queue.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
__author__='shenshijun'
44
importcopy
55

6+
67
classQueue(object):
78
"""
89
使用Python的list快速实现一个队列

‎src/lib/set.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def __iter__(self):
4646
def__str__(self):
4747
return",".join(map(lambdanode:str(node),iter(self)))
4848

49+
4950
defmain():
5051
test_set=Set()
5152
test_set.add(10)
@@ -56,5 +57,3 @@ def main():
5657

5758
if__name__=="__main__":
5859
main()
59-
60-

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp