Merge pull request #24 from sachans/master

[feature]added sorting algorithm
This commit is contained in:
Rohit Tanwar
2018-03-09 20:06:56 +05:30
committed by GitHub
3 changed files with 22 additions and 1 deletions

View File

@ -23,3 +23,4 @@ is_lower_case:[Rohit Tanwar](@kriadmin)
count_by:[Rohit Tanwar](@kriadmin)
insertion_sort:[Meet Zaveri](@meetzaveri),[Rohit Tanwar](@kriadmin)
difference_by:[Rohit Tanwar](@kriadmin)
bubble_sort: [Shobhit Sachan](@sachans)

19
snippets/bubble_sort.md Normal file
View File

@ -0,0 +1,19 @@
### bubble_sort
Bubble_sort uses the technique of comparing and swapping
```python
def bubble_sort(arr):
for passnum in range(len(arr)-1,0,-1):
for i in range(passnum):
if arr[i]>arr[i+1]:
temp = arr[i]
arr[i] = arr[i+1]
arr[i+1] = temp
```
```python
arr = [54,26,93,17,77,31,44,55,20]
bubble_sort(arr)
print("sorted %s" %arr) # [17,20,26,31,44,54,55,77,91]
```

View File

@ -22,4 +22,5 @@ is_upper_case:string
is_lower_case:string
count_by:list
difference_by:list
insertion_sort:list
insertion_sort:list
bubble_sort: list