├── .gitignore
├── LICENSE
├── MANIFEST.in
├── README.md
├── SortingAlgorithms
├── Algorithms.py
└── __init__.py
└── setup.py
/.gitignore:
--------------------------------------------------------------------------------
1 | # cache
2 | .vscode
3 |
4 | # requirement files
5 | Pipfile
6 | pipfile.lock
7 |
8 | # Distribution / packaging files
9 | dist/
10 | build/
11 | *.egg-info/
12 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 Abhishek Tripathi
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/MANIFEST.in:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abhi7585/SortingAlgorithms/218117ed5cc89828ba90713ffd5c3804617f1c7c/MANIFEST.in
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SortingAlgorithms
2 | A sorting algorithm is an algorithm that places the list elements in a certain order. Efficient sorting is critical for maximizing the performance of other algorithms that enable input data to be stored in sorted lists.
3 |
4 | This package will help user to get the results of few sorting algorithms(will be updated in future).
5 |
6 | ## Installation
7 | ```pip install SortingAlgorithms```
8 |
9 | ## How to use it?
10 | First, use the above command to install the package. The package includes a few algorithms that can be used either to understand the working condition or to complete the goal by using a sorting algorithm.
11 |
12 | Below is a brief example of how the package will be used to accomplish the goal.
13 |
14 | ```
15 | from SortingAlgorithms import Algorithms as algo
16 |
17 | data = [22, 5, 34, 12, 90, 33]
18 |
19 | print(algo.bubbleSort(array= data, ascending= True, steps= True))
20 | ```
21 | Output:-
22 | ```
23 | step 1:-
24 | j = 0 : [22, 5, 34, 12, 90, 33]
25 | Swapping: 5 with 22
26 | j = 1 : [5, 22, 34, 12, 90, 33]
27 | j = 2 : [5, 22, 34, 12, 90, 33]
28 | Swapping: 12 with 34
29 | j = 3 : [5, 22, 12, 34, 90, 33]
30 | j = 4 : [5, 22, 12, 34, 90, 33]
31 | Swapping: 33 with 90
32 |
33 |
34 | step 2:-
35 | j = 0 : [5, 22, 12, 34, 33, 90]
36 | j = 1 : [5, 22, 12, 34, 33, 90]
37 | Swapping: 12 with 22
38 | j = 2 : [5, 12, 22, 34, 33, 90]
39 | j = 3 : [5, 12, 22, 34, 33, 90]
40 | Swapping: 33 with 34
41 |
42 |
43 | step 3:-
44 | j = 0 : [5, 12, 22, 33, 34, 90]
45 | j = 1 : [5, 12, 22, 33, 34, 90]
46 | j = 2 : [5, 12, 22, 33, 34, 90]
47 |
48 |
49 | step 4:-
50 | j = 0 : [5, 12, 22, 33, 34, 90]
51 | j = 1 : [5, 12, 22, 33, 34, 90]
52 |
53 | step 5:-
54 | j = 0 : [5, 12, 22, 33, 34, 90]
55 |
56 |
57 | step 6:-
58 |
59 |
60 | [5, 12, 22, 33, 34, 90]
61 | ```
62 |
63 | The parameters which user can use while calling the functions are:
64 | * array - The array of number is given as input.
65 | * ascending - The order in which the array needs to sorted. Bydefault it is False i.e descending.
66 | * steps - If working of sorting is need to be scene steps can be used. Bydefault it is False.
67 |
68 | ## Algorithms which are available in package:
69 | 1) Bubble Sort
70 | 2) Selection Sort
71 | 3) Insertion Sort
72 |
73 | ## Version Update details
74 |
75 | 1) version 1.0 - 04/02/2021
76 |
77 |
78 | ## License
79 |
80 | © 2021 Abhishek Tripathi
81 |
82 | This repository is licensed under the MIT license. See LICENSE for details.
83 |
84 |
Show some ❤️ by starring this repo!
85 |
--------------------------------------------------------------------------------
/SortingAlgorithms/Algorithms.py:
--------------------------------------------------------------------------------
1 |
2 | # Bubble Sort Algorithm Function
3 |
4 | def bubbleSort(array, ascending=False, steps=False):
5 |
6 | if ascending == True and steps == True:
7 | for i in range(len(array)):
8 | print("step {}:-" .format(i+1))
9 | for j in range(0, len(array) - i - 1):
10 | print("j = {} : {} ".format(j, array))
11 | # sorting in ascending order
12 | if array[j] > array[j + 1]:
13 | # swapping
14 | array[j], array[j + 1] = array[j + 1], array[j]
15 | print("Swapping: {} with {} ".format(array[j], array[j+1]))
16 | print("\n")
17 | else:
18 | return array
19 |
20 | elif ascending == False and steps == True:
21 | for i in range(len(array)):
22 | print("step {}:-" .format(i+1))
23 | for j in range(0, len(array) - i - 1):
24 | print("j = {} : {} ".format(j, array))
25 | # sorting in descending order
26 | if array[j] < array[j + 1]:
27 | # swapping
28 | array[j], array[j + 1] = array[j + 1], array[j]
29 | print("Swapping: {} with {} ".format(array[j], array[j+1]))
30 | print("\n")
31 | else:
32 | return array
33 |
34 | elif ascending == True and steps == False:
35 | for i in range(len(array)):
36 | for j in range(0, len(array) - i - 1):
37 |
38 | # sorting in ascending order
39 | if array[j] > array[j + 1]:
40 |
41 | # swapping
42 | array[j], array[j + 1] = array[j + 1], array[j]
43 | else:
44 | return array
45 |
46 | else:
47 | for i in range(len(array)):
48 | for j in range(0, len(array) - i - 1):
49 |
50 | # sorting in descending order
51 | if array[j] < array[j + 1]:
52 |
53 | # swapping
54 | array[j], array[j + 1] = array[j + 1], array[j]
55 | else:
56 | return array
57 |
58 |
59 | # Selection Sort Algorithm Function
60 |
61 |
62 | def selectionSort(array, ascending=False, steps=False):
63 | size = len(array)
64 | if ascending == True and steps == True:
65 | for i in range(size):
66 | min_index = i
67 | print("step {}:-" .format(i+1))
68 |
69 | for j in range(i + 1, size):
70 |
71 | print("j = {} : {} , Min Value Index: {} ".format(
72 | j, array, min_index))
73 |
74 | # sorting in ascending order
75 | if array[j] < array[min_index]:
76 | min_index = j
77 | # swapping
78 | array[i], array[min_index] = array[min_index], array[i]
79 | print("Swapping: {} with {} ".format(array[i], array[min_index]))
80 | print("\n")
81 | else:
82 | return array
83 |
84 | elif ascending == True and steps == False:
85 | for i in range(size):
86 | min_index = i
87 | for j in range(i + 1, size):
88 |
89 | # sorting in ascending order
90 | if array[j] < array[min_index]:
91 | min_index = j
92 | # swapping
93 | array[i], array[min_index] = array[min_index], array[i]
94 | else:
95 | return array
96 |
97 | elif ascending == False and steps == True:
98 | for i in range(size):
99 | max_index = i
100 | print("step {}:-" .format(i+1))
101 | for j in range(i + 1, size):
102 |
103 | print("j = {} : {} , Max Value Index: {} ".format(
104 | j, array, max_index))
105 |
106 | # sorting in descending order
107 | if array[j] > array[max_index]:
108 | max_index = j
109 | print("\n")
110 | # swapping
111 | array[i], array[max_index] = array[max_index], array[i]
112 | else:
113 | return array
114 |
115 | else:
116 | for i in range(size):
117 | min_index = i
118 | for j in range(i + 1, size):
119 |
120 | # sorting in descending order
121 | if array[j] > array[min_index]:
122 | min_index = j
123 | # swapping
124 | array[i], array[min_index] = array[min_index], array[i]
125 | else:
126 | return array
127 |
128 | # Insertion Sort Algorithm Function
129 |
130 |
131 | def insertionSort(array, ascending=False, steps=False):
132 |
133 | if ascending == True and steps == True:
134 | for i in range(1, len(array)):
135 | print("step {}:-" .format(i))
136 | key = array[i]
137 | j = i - 1
138 |
139 | while j >= 0 and key < array[j]:
140 | print("{} ".format(array))
141 |
142 | array[j + 1] = array[j]
143 | j = j - 1
144 |
145 | array[j + 1] = key
146 | print("Key = {} ".format(key))
147 |
148 | print("\n")
149 | else:
150 | return array
151 |
152 | elif ascending == True and steps == False:
153 | for i in range(1, len(array)):
154 | key = array[i]
155 | j = i - 1
156 |
157 | while j >= 0 and key < array[j]:
158 | array[j + 1] = array[j]
159 | j = j - 1
160 | array[j + 1] = key
161 | else:
162 | return array
163 |
164 | elif ascending == False and steps == True:
165 | for i in range(1, len(array)):
166 | print("step {}:-" .format(i))
167 | key = array[i]
168 | j = i - 1
169 |
170 | while j >= 0 and key > array[j]:
171 | print("{} ".format(array))
172 |
173 | array[j + 1] = array[j]
174 | j = j - 1
175 | else:
176 | print(array)
177 |
178 | array[j + 1] = key
179 | print("Key = {} ".format(key))
180 | print("\n")
181 | else:
182 | return array
183 |
184 | else:
185 | for i in range(1, len(array)):
186 | key = array[i]
187 | j = i - 1
188 |
189 | while j >= 0 and key > array[j]:
190 | array[j + 1] = array[j]
191 | j = j - 1
192 | array[j + 1] = key
193 | else:
194 | return array
195 |
--------------------------------------------------------------------------------
/SortingAlgorithms/__init__.py:
--------------------------------------------------------------------------------
1 | # __init__.py
2 |
3 | # Module version
4 |
5 | __version__ = "1.0"
6 |
--------------------------------------------------------------------------------
/setup.py:
--------------------------------------------------------------------------------
1 | import pathlib
2 | from setuptools import setup
3 |
4 | # The directory containing this file
5 | HERE = pathlib.Path(__file__).parent
6 |
7 | # The text of the README file
8 | README = (HERE / "README.md").read_text()
9 |
10 | # This call to setup() does all the work
11 | setup(
12 | name="SortingAlgorithms",
13 | version="1.0",
14 | description="This package will help user to get the results of few sorting algorithms.",
15 | long_description=README,
16 | long_description_content_type="text/markdown",
17 | url="https://github.com/abhi7585/SortingAlgorithms",
18 | author="Abhishek Tripathi",
19 | author_email="abhi.workonly@gmail.com",
20 | license="MIT",
21 | classifiers=[
22 | "License :: OSI Approved :: MIT License",
23 | "Programming Language :: Python"
24 | ],
25 | packages=["SortingAlgorithms"],
26 | include_package_data=True,
27 | install_requires=[],
28 | )
29 |
--------------------------------------------------------------------------------