Find the data structure Quick Sort What are the sorting methods of the data structure

Updated on technology 2024-05-23
5 answers
  1. Anonymous users2024-02-11

    This one is in C.

    #include

    #include

    #define x

    #define n 100

    #define y

    int kuaipai(char *a,int i,int j,int *k) Quick sort function

    char v;

    int i=i;

    int j=j;

    v=*(a+(i+j)/2);

    while(1)

    while(iv)

    i++;while(j>i&&*a+j)j)

    break;

    if(i= end) {

    else {

    int pivot = a[end];

    int result = getpivot(begin, end, pivot);

    quicksort(begin, result - 1);

    quicksort(result + 1, end);

    private int getpivot(int begin, int end, int pivot) {

    begin = begin - 1;

    int o = end;

    while (true) {

    while (a[++begin] while (end > 0 &&a[--end] >pivot) {

    if (begin >= end) {

    break;

    else {

    swap(begin, end);

    swap(begin, o);

    return begin;

    private void swap(int begin, int end) {

    int t = a[begin];

    a[begin] = a[end];

    a[end] = t;

    public int geta()

    return a;

    public void seta(int a) {

    a;

  2. Anonymous users2024-02-10

    The first platoon is 67, 50, 65, 75, 78, 56, 89, the second platoon is 50, 65, 67, 75, 56, 78, 89, the third platoon is 50, 65, 67, 56, 75, 78, 89, the fourth platoon is 50, 65, 56, 67, 75, 78, 89, the fifth platoon is 50, 56, 65, 67, 75, 78, 89

  3. Anonymous users2024-02-09

    1. Heapsort refers to a sorting algorithm designed by using the data structure of heap tree (heap), which is a kind of selection sorting. You can use the characteristics of arrays to quickly locate the elements of a specified index. The heap is divided into large root heaps and small root heaps, which are complete binary trees.

    2. Data structure and algorithm, in fact, this belongs to the content of the algorithm. The main internal sorting methods are: bubble sorting, selection sorting, inserting sorting, quicksorting, merge sorting.

    Of course, there are many more complex sorting methods (binary tree sorting, heap sorting. Many) it would be nice to master the first 4 mainly.

    3. Merge sorting is a common method of sorting, and its main idea is: divide an unordered sequence of numbers in turn until each sequence has only one elemental source mill, and then merge the two sequences into an ordered sequence, and so on. Bucket tracks.

  4. Anonymous users2024-02-08

    Recursive formula. Since the design to recursion. There are two necessary conditions for subconsciously wanting to use recursion.

    If we want to sort a set of data in an array with subscripts from startindex to endindex, we choose any data between startindex and endindex as the pivot. Typically, the last element of the array is selected.

    We iterate through the data from startindex to endindex, putting the less pivot to the left, the larger pivot to the right, and the pivot to the middle.

    After this step, the data between the startindex and the endindex of the array is divided into three parts, all of which are smaller than the pivot, the middle is the pivot, and the second is larger than the pivot.

    According to the idea of divide and conquer and recursive, we can use recursively sort the data between startindex and pivot-1 and the data between pivot+1 and endindex until the interval is narrowed to 1, which means that all the data are ordered.

    With the core idea, it is now givenRecursive formula. , andExit Conditions

    t(n) =2*t(n/2) +n

    The derivation logic and merge order are consistent. The time complexity is:o(nlogn)

    Quick sort is an in-place sorting, a movement implemented in the form of swapping, without opening additional memory space, and the space complexity is:o(1)

    The process of merging and sorting isFrom bottom to top, work on the sub-issues first, and then merge them.

    Fast row is just the opposite, its processing process is:From top to bottom, partition first, and then deal with the subissue.

    Merge sorting is not in-place sorting and requires additional memory space.

    Quick Sort is an in-place sort.

  5. Anonymous users2024-02-07

    Quicksort, a computer science vocabulary that is applicable to languages such as Pascal and C++, is an improvement on the bubbling sort algorithm.

    1. First, set a demarcation value, and divide the array into left and right parts through the demarcation value.

    2. Concentrate the data greater than or equal to the cut-off value to the right side of the array, and the data less than the cut-off value to the left side of the array. In this case, all elements in the left section are less than the cut-off value, while all elements in the right section are greater than or equal to the cut-off value.

    3. Then, the data on the left and right can be sorted independently. For the array data on the left, you can take a demarcation draft assignment value and divide the part of the data into two parts, the left and right parts, and place the smaller value on the left and the larger value on the right. The array data on the right can be treated similarly.

    4. Repeating the above process, it can be seen that this is a recursive definition. After recursively ordering the left part, recursively order the right part. When the data in the left and right parts is sorted, the entire array is sorted.

    Sort demo

    Suppose the initial sequence is: 5, 3, 7, 6, 4, 1, 0, 2, 9, 10, 8.

    At this time, ref=5,i=1,j=11, look from back to front, the first number smaller than 5 is x8=2, so the sequence is: 2,3,7,6,4,1,0,5,9,10,8.

    At this time, i=1, j=8, from front to back, the first number greater than 5 is x3=7, so the sequence is: 2, 3, 5, 6, 4, 1, 0, 7, 9, 10, 8.

    At this time, i=3, j=8, look forward from the 8th digit, the first number smaller than 5 is x7=0, therefore: 2, 3, 0, 6, 4, 1, 5, 7, 9, 10, 8.

    In this case, i=3, j=7, look backwards from the 3rd digit, the first number greater than 5 is x4=6, therefore: 2, 3, 0, 5, 4, 1, 6, 7, 9, 10, 8.

    At this time, i=4, j=7, looking forward from the 7th position, the first number smaller than 5 is x6=1, therefore: 2, 3, 0, 1, 4, 5, 6, 7, 9, 10, 8.

    At this time, i=4, j=6, look backwards from the 4th position, until the 6th digit has a number larger than 5, at this time, i=j=6, ref becomes a dividing line, the number before it is smaller than it, and the number after it is larger than it, for the two parts of the number, you can use the same method to sort.

Related questions
12 answers2024-05-23

A data structure is the way a computer stores and organizes data. >>>More

9 answers2024-05-23

These things are expressed in ASCII codes, and then determined by scan input and if statements.

5 answers2024-05-23

I would like to introduce you to Yan Weimin's textbook "Data Structure" (C language version), which is currently a classic textbook with a good reputation in China. >>>More

8 answers2024-05-23

The creation sequence table is as follows:

by the array element a[0..n-1] to create a sequential table l. Each element in a is placed sequentially in a sequential table, and n is assigned to the length field of the sequential table. The algorithm is: >>>More

9 answers2024-05-23

1) Can't accept the way it's described. The description of data structures is mostly in the form of abstractions, and we are used to using natural language expressions, which makes it difficult to accept the abstract expressions of data structures. More than one student asked me, what exactly is the type of "elemtype" in the book? >>>More