Complete sorting using Python

Source: Internet
Author: User

1 classSort (object):2 3 @staticmethod4     defbubble_sort (LS):5Lenth =len (LS)6         ifLenth = =0:7             return []8          whileLenth:9              forIinchRange (lenth-1):Ten                 ifLs[i] > Ls[i+1]: OneLs[i], ls[i+1] = ls[i+1], Ls[i] ALenth-= 1 -         returnls -  the @staticmethod -     defselect_sort (LS): -         if  notls: -             return [] +Lenth =len (LS) -i =0 +          whileI < Lenth-1: AMin_v =Ls[i] at              forNinchRange (i+1, lenth): -                 ifLs[n] <Min_v: -LOC, Min_v =N, Ls[n] -             ifLs[i]! =Min_v: -Ls[i], Ls[loc] =Ls[loc], Ls[i] -i + = 1 in         returnls -  to @staticmethod +     definsert_sort (LS): -         if  notls: the             return [] *i = 1 $Lenth =len (LS)Panax Notoginseng          whileI <Lenth: -              forNinchRange (0, i): the                 ifLs[n] > Ls[n+1]: +Ls[n], ls[n+1] = ls[n+1], Ls[n] Ai + = 1 the         returnls +  -  $  $  - if __name__=='__main__': -ls = [1, 9, 5, 4, 3, 7, 6] thes =Sort () -     Print(S.bubble_sort (LS))Wuyi     Print(S.select_sort (LS)) the     Print(S.insert_sort (LS))

Know:

    1. Bubble sort is the maximum value (minimum value) that is exchanged to the end of the line (at the beginning of the row) by adjacent;
    2. Select sorting is the maximum value (minimum) to be placed at the end of the line (at the beginning);
    3. An insert sort is an adjacent interchange that inserts the next number into an already sequenced sequence.

Complete sorting using Python

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.