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

Commit a0ec2a4

Browse files
committed
__name__=='__main__'
1 parent e55998a commit a0ec2a4

File tree

5 files changed

+65
-60
lines changed

5 files changed

+65
-60
lines changed

‎Graph/1.0-BasicGraph.py‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,11 @@ def __iter__(self):
4747
return iter(self.vertexList.values())
4848

4949

50-
g = Graph()
51-
for i in 'abcde': # add some vertices
52-
g.addVertex(i)
53-
g.addEdge('a', 'b', 2) # add edge
54-
g.addEdge('a', 'c', 1)
55-
for i in g:
56-
print(i)
50+
if __name__ == '__main__':
51+
g = Graph()
52+
for i in 'abcde': # add some vertices
53+
g.addVertex(i)
54+
g.addEdge('a', 'b', 2) # add edge
55+
g.addEdge('a', 'c', 1)
56+
for i in g:
57+
print(i)

‎Graph/1.1-BasicGraph2DMatrix.py‎

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,24 @@ def display(self):
4141
print(self.adjMatrix)
4242

4343

44-
G = Graph(7)
45-
# before adding edge
46-
print("before adding edge")
47-
G.display()
48-
G.addEdge(0, 1)
49-
G.addEdge(1, 2)
50-
G.addEdge(2, 1, 2)
51-
G.addEdge(3, 5)
52-
G.addEdge(2, 5)
53-
# after adding edge
54-
print("after adding edge")
55-
G.display()
56-
G.removeEdge(0, 1)
57-
# after removing edge
58-
print("after removing edge")
59-
G.display()
60-
print(f"The weight of 2,1 vertices: {G.getWeight(2, 1)}")
61-
print(f"Total Edges: {G.getEdges()}")
62-
print(f"In degree of vertex 1: {G.inDegree(1)}")
63-
print(f"Out degree of vertex 1: {G.outDegree(2)}")
44+
if __name__ == '__main__':
45+
G = Graph(7)
46+
# before adding edge
47+
print("before adding edge")
48+
G.display()
49+
G.addEdge(0, 1)
50+
G.addEdge(1, 2)
51+
G.addEdge(2, 1, 2)
52+
G.addEdge(3, 5)
53+
G.addEdge(2, 5)
54+
# after adding edge
55+
print("after adding edge")
56+
G.display()
57+
G.removeEdge(0, 1)
58+
# after removing edge
59+
print("after removing edge")
60+
G.display()
61+
print(f"The weight of 2,1 vertices: {G.getWeight(2, 1)}")
62+
print(f"Total Edges: {G.getEdges()}")
63+
print(f"In degree of vertex 1: {G.inDegree(1)}")
64+
print(f"Out degree of vertex 1: {G.outDegree(2)}")

‎LinearDataStructure/stack/stack.py‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ def show(self):
2323
print(self.stack)
2424

2525

26-
st = Stack()
27-
st.insertVal(3)
28-
st.insertVal(5)
29-
st.insertVal(7)
30-
st.insertVal(9)
26+
if __name__ == '__main__':
27+
st = Stack()
28+
st.insertVal(3)
29+
st.insertVal(5)
30+
st.insertVal(7)
31+
st.insertVal(9)
3132

32-
print(st.peekVal())
33+
print(st.peekVal())
3334

34-
st.delVal()
35+
st.delVal()
3536

36-
st.show()
37+
st.show()

‎sorting/insertion_sort.py‎

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,17 @@ def showDescending(self):
3737
print(self.numberList)
3838

3939

40-
sortt = InsertionSort()
41-
42-
sortt.insertNum(8)
43-
sortt.insertNum(5)
44-
sortt.insertNum(13)
45-
sortt.insertNum(11)
46-
sortt.insertNum(2)
47-
sortt.insertNum(7)
48-
49-
print('in ascending:\n')
50-
sortt.showAscending()
51-
print('\n in descending:\n')
52-
sortt.showDescending()
40+
if __name__ == '__main__':
41+
i_sort = InsertionSort()
42+
43+
i_sort.insertNum(8)
44+
i_sort.insertNum(5)
45+
i_sort.insertNum(13)
46+
i_sort.insertNum(11)
47+
i_sort.insertNum(2)
48+
i_sort.insertNum(7)
49+
50+
print('in ascending:\n')
51+
i_sort.showAscending()
52+
print('\n in descending:\n')
53+
i_sort.showDescending()

‎sorting/selection_sort.py‎

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,16 @@ def showDescending(self):
2525
print(self.numberList)
2626

2727

28-
ssort = selectionSort()
29-
30-
ssort.insertVal(90)
31-
ssort.insertVal(35)
32-
ssort.insertVal(60)
33-
ssort.insertVal(7)
34-
ssort.insertVal(2)
35-
ssort.insertVal(3)
36-
ssort.insertVal(89)
37-
38-
ssort.showAscending()
39-
ssort.showDescending()
28+
if __name__ == '__main__':
29+
s_sort = selectionSort()
30+
31+
s_sort.insertVal(90)
32+
s_sort.insertVal(35)
33+
s_sort.insertVal(60)
34+
s_sort.insertVal(7)
35+
s_sort.insertVal(2)
36+
s_sort.insertVal(3)
37+
s_sort.insertVal(89)
38+
39+
s_sort.showAscending()
40+
s_sort.showDescending()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /