-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex2.2.py
More file actions
30 lines (27 loc) · 715 Bytes
/
ex2.2.py
File metadata and controls
30 lines (27 loc) · 715 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Dec 15 16:11:40 2019
@author: astro
"""
import numpy as np
fname=fname=str('illustris3_135.dat')
IDs=np.genfromtxt(fname, dtype="float",usecols=(0))
#sorting algorithm
def quicksort(arr):
c=[]
d=[]
m=[]
if(len(arr)>1):
p=arr[0] #pivot chosen & print(p)
for x in arr:
if(x>p):
c.append(x) #array of elements after the pivot
elif(x<p):
d.append(x) #array of elements before the pivot
elif(x==p):
m.append(x) #array with the pivot
return quicksort(d) + m + quicksort(c)
else:
return arr
print(quicksort(IDs))