Skip to content

Commit d5347ef

Browse files
committed
Updated Sorts
1 parent f492ced commit d5347ef

19 files changed

+32
-67
lines changed

docs/Searching.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ Searching
44

55
Learning searching algorithms easily!
66

7-
-----------------
87
Quick Start Guide
98
-----------------
109

@@ -22,7 +21,6 @@ Quick Start Guide
2221
index = binary_search.search(myList, 7)
2322
print(index)
2423
25-
--------
2624
Features
2725
--------
2826

@@ -33,7 +31,7 @@ Features
3331
- Depth First Search (depth_first_search)
3432

3533
* For Searching:
36-
Remember search() function takes two parameters as a sorted list and the target element to be searched.
34+
Remember ``search()`` function takes two parameters as a sorted list and the target element to be searched.
3735

3836
.. code-block:: python
3937

docs/Sorting.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ Sorting
44

55
Just sort the way you want.
66

7-
-----------------
87
Quick Start Guide
98
-----------------
109

@@ -18,7 +17,6 @@ Quick Start Guide
1817
# to sort the list
1918
sorted_list = bubble_sort.sort(myList)
2019
21-
--------
2220
Features
2321
--------
2422

@@ -28,9 +26,13 @@ Features
2826
- Insertion Sort (insertion_sort)
2927
- Merge Sort (merge_sort)
3028
- Quick Sort (quick_sort)
29+
- Bucket Sort (bucket_sort)
30+
- Counting Sort (counting_sort)
31+
- Heap Sort (heap_sort)
32+
- Shell Sort (shell_sort)
3133

3234
* For sorting:
33-
Remember sort() function takes its parameter as a list only.
35+
Remember ``sort()`` function takes its parameter as a list only.
3436

3537
.. code-block:: python
3638

docs/conf.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,15 @@
44
import sys
55
import os
66
import shlex
7-
from recommonmark.parser import CommonMarkParser
8-
9-
source_parsers = {
10-
'.md': CommonMarkParser,
11-
}
127

138
# If extensions (or modules to document with autodoc) are in another directory,
149
# add these directories to sys.path here. If the directory is relative to the
1510
# documentation root, use os.path.abspath to make it absolute, like shown here.
1611
sys.path.insert(0, os.path.abspath('..'))
1712

1813
# -- General configuration ------------------------------------------------
19-
project = 'pygorithm'
20-
version = release = '0.1.dev3'
14+
project = u'pygorithm'
15+
version = release = u'0.1.dev3'
2116

2217
# Add any Sphinx extension module names here, as strings. They can be
2318
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom

docs/index.rst

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,22 @@ Pygorithm
55
``Pygorithm``: A fun way to learn algorithms on the go! Just import the module and start learning, it's that easy.
66

77
A Python module written in pure python and for purely educational purposes.
8-
Get the code, time complexities and much more by just importing the required algorithm.
8+
Get the code, time complexities and much more by just importing the required algorithm. A good way to start
9+
learning Python programming. Learn implementation of all major algorithms in Python.
10+
No need to surf the internet to get the required code. Just install this module and get going.
911

10-
Table of Contents:
11-
------------------
12+
Quick Links
13+
-----------
14+
15+
* `Source Code <https://github.com/OmkarPathak/pygorithm>`_
16+
* `Documentation <http://pygorithm.readthedocs.io/en/latest/>`_
1217

1318
.. toctree::
14-
:titlesonly:
15-
19+
:maxdepth: 2
20+
1621
Sorting
1722
Searching
1823

19-
20-
-----------------
2124
Quick Start Guide
2225
-----------------
2326

@@ -35,7 +38,6 @@ Quick Start Guide
3538
# to sort the list
3639
sorted_list = bubble_sort.sort(myList)
3740
38-
---------------
3941
Getting Started
4042
---------------
4143

@@ -46,8 +48,3 @@ Getting Started
4648
pip3 install pygorithm
4749

4850
* For Python 2, you can use pip instead. Depending on your user permissions, you might need to ``sudo`` before installing
49-
50-
51-
* :ref:`genindex`
52-
* :ref:`modindex`
53-
* :ref:`search`

pygorithm/searching/binary_search.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,18 @@ def search(List, target):
99
right = len(List) - 1 # Last position of the list
1010

1111
try:
12+
found = False
1213
while left <= right: # you can also write while True condition
1314
mid = (left + right) // 2
1415
if target == List[mid]:
16+
found = True
1517
return mid
1618
elif target < List[mid]:
1719
right = mid - 1
1820
else:
1921
left = mid + 1
20-
return -1
22+
if found == False:
23+
return -1
2124
except TypeError:
2225
return -1
2326

1.31 KB
Binary file not shown.
1.72 KB
Binary file not shown.
939 Bytes
Binary file not shown.
1.27 KB
Binary file not shown.
769 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)