Skip to content

Commit 098624a

Browse files
committed
arrays
1 parent abe584e commit 098624a

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

Array Boot Camp EPI.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
3+
#Without using additional space distribute numbers in an array so that even numbers are at teh start and odd numbers are after that
4+
#used partitioning, partitioned data into even, odd and unclassified
5+
6+
7+
def even_odd_array(A):
8+
even_index=0
9+
odd_index=len(A)-1
10+
11+
while even_index<odd_index:
12+
if A[even_index]%2==0:
13+
even_index+=1 #incrementing even index if even number found
14+
15+
else:
16+
A[even_index],A[odd_index]=A[odd_index],A[even_index]
17+
odd_index-=1
18+
print(A)
19+
20+
21+
A=[1,4,3,7,2,10]
22+
even_odd_array(A)

EPI_Array.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
def dutch_flag(A, pivot_index):
2+
p=pivot_index
3+
part=0
4+
for i in range(len(A)):
5+
if A[i]<A[p]:
6+
A[i],A[part]==A[part],A[i]
7+
part+=1
8+
elif A[i]==A[p]:
9+
continue
10+
elif A[i]>A[p]:
11+
continue
12+
A[part],A[p]==A[p],A[part]
13+
print(A)
14+
15+
A = [1, 4, 3, 7, 2, 10, 9, 12, 45, 23, 65, 43, 100, 25, 60]
16+
dutch_flag(A,8)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
# Algo
1+
# py_algo_ds

0 commit comments

Comments
 (0)