QuickSort in Python

”’
Created on May 7, 2017

@author: asharda
”’

def quicksort(array):
if len(array) <= 1:
return array
pivot = array[len(array) / 2]
left = [x for x in array if x < pivot]
middle = [x for x in array if x == pivot]
right = [x for x in array if x > pivot]
return quicksort(left) + middle + quicksort(right)

print quicksort([3,6,8,10,1,2,1])

Advertisements

About qainterviews

Software Geek,QA Expert,Blogger
This entry was posted in Python, Uncategorized. Bookmark the permalink.

One Response to QuickSort in Python

  1. www.Linux.ca says:

    It’s very easy to find outt any matter on web as compared to textbooks, as I found this paragrtaph at thi web site.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s