Skip to content

Commit

Permalink
Merge pull request Burnout-Devil#11 from Akash1437/main
Browse files Browse the repository at this point in the history
Create quicksort.py
  • Loading branch information
Burnout-Devil committed Oct 17, 2022
2 parents c20bb88 + d0364c8 commit 6ccc4be
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
30 changes: 30 additions & 0 deletions Sieve_of_Eratosthenes.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

#include <bits/stdc++.h>
using namespace std;

void SieveOfEratosthenes(int n)
{
bool prime[n+1];
memset(prime, true, sizeof(prime));

for (int p=2; p*p<=n; p++)
{
if (prime[p] == true)
{
for (int i=p*2; i<=n; i += p)
prime[i] = false;
}
}
for (int p=2; p<=n; p++)
if (prime[p])
cout << p << " ";
}

int main()
{
int n = 30;
cout << "Following are the prime numbers smaller "
<< " than or equal to " << n << endl;
SieveOfEratosthenes(n);
return 0;
}
18 changes: 18 additions & 0 deletions move_all.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
def pushZerosToEnd(arr, n):
count = 0

for i in range(n):
if arr[i] != 0:
arr[count] = arr[i]
count+=1

while count < n:
arr[count] = 0
count += 1

arr = [1, 9, 8, 4, 0, 0, 2, 7, 0, 6, 0, 9]
n = len(arr)
pushZerosToEnd(arr, n)
print("Array after pushing all zeros to end of array:")
print(arr)

33 changes: 33 additions & 0 deletions quicksort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
def partition(array,low,high):

pivot= array[high]

i=low-1

for j in range(low,high):
if array[j] <= pivot:

i=i+1
(array[i],array[j]) = (array[high],array[i+1])

return i+1
def quickSort(array,low,high):
if low<high:

pi = partition(array,low,pi-1)

quickSort(array,low,pi - 1)

quickSort(array,pi+1,high)

data=[8,7,2,1,0,9,6]
print("Unsorted Array)
print(data)

size =len(data)

quickSort(data,0,size-1)
print('sorted array is')
print(data)


0 comments on commit 6ccc4be

Please sign in to comment.