Python Quick Sort

Source: Internet
Author: User

Quick Sort is a sub-governance idea

Basic Idea of divide and conquer Law
The basic idea of the division and control law is to break down the original problem into several subproblems with smaller sizes but similar structures as the original problem. Recursively solve these subproblems, and then combine the solutions of these subproblems into the solutions of the original problem.

SEQ = seq_a + [k] + seq_ B

All item in seq_a <K

All item in seq_ B> K

Def quicksort (SEQ): If Len (SEQ) <= 1: Return seq K = seq [0] seq_a, seq_ B = [], [] For I in range (1, len (SEQ): If seq [I]> = K: seq_ B .append (SEQ [I]) else: seq_a.append (SEQ [I]) print seq_a, seq_ B return quicksort (seq_a) + [k] + quicksort (seq_ B)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.