: # @param num, a list of integer # @return an integer def maximumgap (self, num): N = Len (nu m) if N Base sortThe data structure of the radix sort Min is described in detail. The main idea is to use the number of the keyword base to allocate. The base of the keyword here is usually the cardinality of the binary. For example, the decimal word is 10, binary is 2. The use of chain-base sorting is typically t
The ordered elements implement the comparable interface to achieve versatility.The most basic sort is bubble sort, here's the idea:
Compares the adjacent elements. If the first one is bigger than the second one, swap them both.
Do the same for each pair of adjacent elements, starting with the last pair from the first pair to the end. At this point, the last element should be the maximum number.
Bubble sort (Bubble sort)Bubble sort (Bubble sort) is a simpler sort algorithm in the field of computer science.It repeatedly visited the sequence to be sorted, two elements in a note, and exchanged them if they were in the wrong order. The job of visiting the sequence is to
This paper implements eight commonly used sorting algorithms: Insert sort, bubble sort, select Sort, hill sort, quick sort, merge sort, heap sort and lst cardinal order.
The first is t
First, overview: This paper mainly introduces the principle of several kinds of sorting algorithms and Java implementation, including: Bubble sort, select sort, insert sort, quick sort, merge sort, etc. Second, bubble sort:(1) Pri
Algorithm-compare two sort algorithms: Select sort and insert sort, Sort Algorithm
Now we have implemented two sorting algorithms. We naturally want to know which sort is faster to choose and insert sort. This is the first time th
Each programming linguistics to the array, will talk about the sorting algorithm, when learning C language, card in the sorting algorithm. today, Let's summarize how three sorting algorithms are implemented in Javascript.1. Bubble sort (default Ascending order Oh) Principle:The principle of bubble sort, as the name implies, is the decimal to go up, large number toward Sinking. Starting with the first number
1. Bubble sortBasic idea: For each order of the trip, start with the first number, and then compare the size of the previous number to the next.If the previous number is larger than the last one, it is exchanged. After that, the largest number will appear at the bottom of the last position.In the second round, the last number is removed, the number of the first n-1 is followed by the above steps to find the maximum number, which will appear in the penultimate position.After the n-1 round, the so
These few very basic sorts are very useful, and I've re-organized the code1#include 2#include 3 4 using namespacestd;5 6 voidBouble_sort (int* Arry,intLenth)//Bubble Sort7 {8 inti,k;9 Ten intFlag =0; One A for(i = lenth-1; I >=0; i--) - { - for(k=0; k) the { - if(Arry[k] > arry[k+1]) - { -Swap (arry[k],arry[k+1]);//If there is a larger case than the previous one, exchange two digits + -Flag =1;//The role of flag
Insert sort + bubble sort + select sort, insert sort bubble select
When inserting the sort work mechanism and playing cards, sorting in the hand is similar. When we started to touch the cards, our left hand was empty and placed down on the table. Next, we touched a card fro
; i The comment is an improvement to the bubbling sort, when no call to the SWAP function indicates that the order has been queued. This can be achieved in the best case time complexity of T (n) =o (n)Select Sort Find the smallest one from all the sequences, then place it in the first position, then look at the smallest of the remaining elements and place it in the second position ... And so onChoosing a
reduced (the last number is removed), and then the first number is adjusted downwards, the largest number is the last. Until there is only one number in the heap.The process of building the heap is from the last non-leaf node until the node is adjusted downwards. Let's say we're going to sort in ascending order. That is, when the downward adjustment, the small swap to the parent node.650) this.width=650; "src=" http://s2.51cto.com/wyfs02/M01/7E/A0/wK
Related articles:
Common sort algorithm (0) (summary and comparison of various sorting algorithms)
Common sort algorithm (i) (bubble sort, insert sort)
Common sort Algorithm (ii) (select sort)
Common
This is a creation in
Article, where the information may have evolved or changed.
The algorithm is the soul of the program, and the sorting algorithm is the most basic algorithm. There are many kinds of sorting algorithms, this article introduces 4 sorting algorithms: Bubble sort, select sort, quick sort and insert sort
The algorithm is the soul of the program, and the sorting algorithm is the most basic algorithm. There are many kinds of sorting algorithms, this article introduces 4 sorting algorithms: Bubble sort, select sort, quick sort and insert sort, take small to large as an example.First, bubble sortThe bubble
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.