-
Notifications
You must be signed in to change notification settings - Fork 242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sorting_Techniques #23
Conversation
@Prathamesh-510 you need to star the repo for following code of conduct! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here i contribute in sorting techniques (bubble sort)
if arr[j] > arr[j + 1]: | ||
swaps += 1 | ||
arr[j], arr[j + 1] = arr[j + 1], arr[j] | ||
return comparisons, swaps |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def bubbleSort( sorti ):
n = len( sorti )
for i in range( n - 1 ) :
flag = 0
for j in range(n - 1) :
if sorti[j] > sorti[j + 1] :
tmp = sorti[j]
sorti[j] = theSeq[j + 1]
sorti[j + 1] = tmp
flag = 1
if flag == 0:
break
return sorti
comparisons = 0 | ||
swaps = 0 | ||
for i in range(n): | ||
for j in range(0, n - i - 1): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import array as arr;
def bubble_sort(arr):
n = len(arr)
flag=0
comparisons = 0
swaps = 0
for i in range(n):
for j in range(0, n - i - 1):
comparisons += 1
if arr[j] > arr[j + 1]:
flag=1
swaps += 1
arr[j], arr[j + 1] = arr[j + 1], arr[j]
if flag==0:
break
return comparisons, swaps, arr
a = arr.array('i', [1,2,6,8,9])
bubble_sort(a)
@riya-kumari023 and @Kavu-13 make sure you star the repo to follow Code of Conduct |
Here I contributed the all sorting algorithms in the python.