Skip to content
This repository has been archived by the owner on Apr 29, 2020. It is now read-only.

Commit

Permalink
Merge pull request #84 from rahulroxx/master
Browse files Browse the repository at this point in the history
Reformated Code and updated .gitignore
  • Loading branch information
aktech committed May 12, 2016
2 parents 3e9f068 + 82a862c commit f27d051
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 20 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,7 @@ sample.tex

# Built doc files (cd doc; make html)
docs/build/
docs/sphinx/
docs/sphinx/

# Pycharm Generated files
.idea/
2 changes: 1 addition & 1 deletion pydsa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
from .linear_search import linear_search
from .queue import queue
from .counting_sort import counting_sort
from .stack import Stack
from .stack import Stack
1 change: 1 addition & 0 deletions pydsa/bst.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class BSTNode(object):
"""
Class to create a Binary Search Tree Node.
"""

def __init__(self, key, left=None, right=None):
self.left = left
self.right = right
Expand Down
8 changes: 4 additions & 4 deletions pydsa/bubble_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ def bubble_sort(a):
"""
for k in range(len(a)):
flag = 0
for i in range(0, len(a)-k-1):
if(a[i] > a[i+1]):
a[i], a[i+1] = a[i+1], a[i]
for i in range(0, len(a) - k - 1):
if (a[i] > a[i + 1]):
a[i], a[i + 1] = a[i + 1], a[i]
flag = 1
if(flag == 0):
if (flag == 0):
break
return a
12 changes: 6 additions & 6 deletions pydsa/insertion_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ def insertion_sort(a):
"""
for i in range(1, len(a)):
element = a[i]
j = i
while j > 0 and a[j-1] > element:
a[j] = a[j-1]
j = j - 1
a[j] = element
element = a[i]
j = i
while j > 0 and a[j - 1] > element:
a[j] = a[j - 1]
j = j - 1
a[j] = element
return a
4 changes: 2 additions & 2 deletions pydsa/merge_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def merge_sort(a):
"""
l = len(a)
if l >= 2:
L = a[0:l//2]
R = a[l//2:]
L = a[0:l // 2]
R = a[l // 2:]
a = _merge(merge_sort(L), merge_sort(R))
return a
1 change: 1 addition & 0 deletions pydsa/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class queue(object):
>>> q.dequeue()
5
"""

def __init__(self):
self.List = []

Expand Down
6 changes: 3 additions & 3 deletions pydsa/quick_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ def quick_sort(a, start=0, end=None):
"""
if end is None:
end = len(a) - 1
if(start < end):
if (start < end):
pIndex = _partition(a, start, end)
quick_sort(a, start, pIndex-1)
quick_sort(a, pIndex+1, end)
quick_sort(a, start, pIndex - 1)
quick_sort(a, pIndex + 1, end)
return a


Expand Down
2 changes: 1 addition & 1 deletion pydsa/selection_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ def selection_sort(a):
"""
for i in range(len(a)):
for j in range(i, len(a)):
if(a[j] < a[i]):
if (a[j] < a[i]):
a[i], a[j] = a[j], a[i]
return a
1 change: 1 addition & 0 deletions pydsa/sleep_sort.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from time import sleep
from threading import Timer


# Sleep Sort ;)
# Complexity: O(max(input)+n)

Expand Down
1 change: 1 addition & 0 deletions pydsa/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Stack(object):
>>> s.pop()
19
"""

def __init__(self):
self.List = []

Expand Down
4 changes: 2 additions & 2 deletions pydsa/tests/test_binary_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def test_binary_search():
item = randint(1, 10)
a = sorted(a)
ans = binary_search(a, item)
if(ans == -1):
if (ans == -1):
assert item not in a
else:
assert a[ans] == item
Expand All @@ -19,7 +19,7 @@ def test_binary_search_recursive():
a = sorted(a)
ans_through_method_1 = binary_search(a, item, True)
ans_through_method_2 = binary_search(a, item, True, 0, len(a) - 1)
if(ans_through_method_1 == ans_through_method_2 == -1):
if (ans_through_method_1 == ans_through_method_2 == -1):
assert item not in a
else:
assert a[ans_through_method_1] == item == a[ans_through_method_2]

0 comments on commit f27d051

Please sign in to comment.