From a7c77faa3bc678f9bcd2289ca46248805fe68090 Mon Sep 17 00:00:00 2001 From: Brian Hopper Date: Tue, 1 Oct 2019 14:24:43 -0700 Subject: [PATCH 1/4] Create quicksort.py Quick and dirty implementation of a quicksort algorithm --- allalgorithms/sorting/quicksort.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 allalgorithms/sorting/quicksort.py diff --git a/allalgorithms/sorting/quicksort.py b/allalgorithms/sorting/quicksort.py new file mode 100644 index 0000000..28582e9 --- /dev/null +++ b/allalgorithms/sorting/quicksort.py @@ -0,0 +1,21 @@ +def partition(xs, start, end): + follower = leader = start + while leader < end: + if xs[leader] <= xs[end]: + xs[follower], xs[leader] = xs[leader], xs[follower] + follower += 1 + leader += 1 + xs[follower], xs[end] = xs[end], xs[follower] + return follower + +def _quicksort(xs, start, end): + if start >= end: + return + p = partition(xs, start, end) + _quicksort(xs, start, p-1) + _quicksort(xs, p+1, end) + +def quicksort(xs): + _quicksort(xs, 0, len(xs)-1) + +# To use: create a list and send it to quicksort: quicksort(list placed here) From 49e476b1c56896449270157e38d7aaf17a27f370 Mon Sep 17 00:00:00 2001 From: Brian Hopper Date: Tue, 1 Oct 2019 16:58:24 -0700 Subject: [PATCH 2/4] Update quicksort.py Added the required header, which I originally forgot to include! --- allalgorithms/sorting/quicksort.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/allalgorithms/sorting/quicksort.py b/allalgorithms/sorting/quicksort.py index 28582e9..6990462 100644 --- a/allalgorithms/sorting/quicksort.py +++ b/allalgorithms/sorting/quicksort.py @@ -1,3 +1,11 @@ +# -*- coding: UTF-8 -*- +# +# Quick Sort Algorithm +# The All â–²lgorithms library for python +# +# Contributed by: Brian D. Hopper +# Github: @bubbabeans +# def partition(xs, start, end): follower = leader = start while leader < end: From 341b64b79a6d173cf8162968b01b0adaa80b23d5 Mon Sep 17 00:00:00 2001 From: Brian Hopper Date: Tue, 1 Oct 2019 17:09:41 -0700 Subject: [PATCH 3/4] Quicksort documentation --- docs/sorting/Quicksort | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 docs/sorting/Quicksort diff --git a/docs/sorting/Quicksort b/docs/sorting/Quicksort new file mode 100644 index 0000000..e985551 --- /dev/null +++ b/docs/sorting/Quicksort @@ -0,0 +1,26 @@ +Quicksort + +A quicksort is a quicker method of sorting, and there are four different ways of implementing it. The example given uses a pivot point. + +A pivot point is created in the middle of an array, and all larger items go after the pivot point, and smaller items are placed in front +of the pivot point. + +The pivot point is then moved to the middle of either the smaller or larger items, and the sort is run again on that half. + +This continues over and over again until everything is in the proper place. + +Usage +from allalgorithms.sorting import quicksort + +arr = [77, 2, 10, -2, 1, 7] + +print(quicksort(arr)) +# -> [-2, 1, 2, 7, 10, 77] + +API + +quicksort(array) +Returns a sorted array + +Params: +array: Unsorted Array From 454cb1098ec16874db58ffb7622ab8f18e255f26 Mon Sep 17 00:00:00 2001 From: Abraham Hernandez Date: Wed, 2 Oct 2019 00:49:06 -0400 Subject: [PATCH 4/4] converting the file to markdown --- docs/sorting/{Quicksort => quicksort.md} | 25 ++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) rename docs/sorting/{Quicksort => quicksort.md} (80%) diff --git a/docs/sorting/Quicksort b/docs/sorting/quicksort.md similarity index 80% rename from docs/sorting/Quicksort rename to docs/sorting/quicksort.md index e985551..e09bc38 100644 --- a/docs/sorting/Quicksort +++ b/docs/sorting/quicksort.md @@ -1,4 +1,4 @@ -Quicksort +# Quicksort A quicksort is a quicker method of sorting, and there are four different ways of implementing it. The example given uses a pivot point. @@ -9,18 +9,31 @@ The pivot point is then moved to the middle of either the smaller or larger item This continues over and over again until everything is in the proper place. -Usage +## Install + +``` +pip install allalgorithms +``` + +## Usage + +```py from allalgorithms.sorting import quicksort arr = [77, 2, 10, -2, 1, 7] print(quicksort(arr)) # -> [-2, 1, 2, 7, 10, 77] +``` -API +## API +``` quicksort(array) -Returns a sorted array +``` + +> Returns a sorted array + +##### Params: -Params: -array: Unsorted Array +- `array`: Sorted Array pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy