In the age of twenty-two, what should I worry about, what should cheer for?
Being a person of his 22, these days I tend to reflect on my past life. What kind of person has the past time shaped me in? What kind of future will I strive for?
Being a person of his 22, these days I tend to reflect on my past life. What kind of person has the past time shaped me in? What kind of future will I strive for?
#-------------------------------------------------------------------------------
# Name: QuickSort
# Purpose: I SHALL NEVER FORGET IT AGAIN.
#
# Author: Eddie
#-------------------------------------------------------------------------------
def qsort(x, p1, p2):
start = p1; end = p2;
mid = (p1 + p2) // 2
while (p1 <= p2):
#Mustn't use <= or >= otherwise may get IndexError
while (x[p1] < x[mid]): p1 += 1
while (x[p2] > x[mid]): p2 -= 1
if (p1 <= p2):
x[p1], x[p2] = x[p2], x[p1]
p1 += 1; p2 -= 1
if (p2 > start): qsort(x, start, p2)
if (p1 < end): qsort(x, p1, end)
if __name__ == '__main__':
import random
x = [random.randint(1, 1000) for i in range(1, 30)]
p1 = 0; p2 = len(x) - 1;
qsort(x, p1, p2)
print(x)
I guess I should try my best to remember where the equation is.