Pascal quick row program, ask for free pascal fast row of ideas, programs, it is best to write good

Updated on technology 2024-04-08
2 answers
  1. Anonymous users2024-02-07

    vara:array[1..100] of integer;

    n,i:integer;

    procedure qsort(head,last:integer);

    vari,j,x:integer;

    beginif head>=last then exit;

    x:=a[head];

    i:=head;j:=last;

    while i=x) do dec(j);

    a[i]:=a[j];

    while (ia[j]:=a[i];

    end;a[i]:=x;

    qsort(head,i-1);qsort(i+1,last);Recursion.

    end;begin

    readln(n);

    for i:=1 to n do read(a[i]);

    qsort(1,n);

    for i:=1 to n do write(a[i],' ');

    end.It can be modified as needed.

  2. Anonymous users2024-02-06

    Quick sort is a neat improvement over bubbling sorting. by c a.

    r.Hoare was presented in 1962. Its basic idea is:

    Divide the data to be sorted into two independent parts through a sorting, all the data of one part are smaller than all the data of the other part, and then quickly sort the two parts of the data respectively according to this method, and the whole sorting process can be carried out recursively, so as to achieve that the whole data becomes an ordered sequence.

    The algorithm process is as follows:

    Let the array to be sorted be a[0]......a[n-1], first select an arbitrary data (usually the first data) as the key data, and then put all the numbers smaller than it in front of it, and all the numbers larger than it put after it, this process is called a quick sort. The algorithm for a quick sort is:

    1) Set two variables i and j, at the beginning of sorting: i=1, j=n-1;

    2) Take the first array element as the key data and assign a value to x, i.e. x=a[0];

    5) Repeat step until i=j;

    For example, the values of array a to be sorted are: (initial key data: x=49).

    a[0] 、a[1]、 a[2]、 a[3]、 a[4]、 a[5]、 a[6]:

    After the first exchange: 27 38 65 97 76 13 49

    Follow the third step of the algorithm to find it from the back).

    After the second exchange: 27 38 49 97 76 13 65

    According to the fourth step of the algorithm, start from the front to find the value of x, 65>49, and the two answer collapse keys are exchanged, at this time: i=3 )

    After the third exchange: 27 38 13 97 76 49 65

    Follow the fifth step of the algorithm and execute the third step of the algorithm again.

    After the fourth exchange: 27 38 13 49 76 97 65

    According to the fourth step of the algorithm, start from the front to find the value greater than x, 97>49, the two are exchanged, at this time: j=4 )

    At this time, when the third step is executed, it is found that i=j, so as to end a lying quick sort, then the result after a quick sort is: 27 38 13 49 76 97 65, that is, so the numbers greater than 49 are all after 49, so the numbers less than 49 are all in front of 49.

    Quicksort is to recursively call this process - in the 49 as the midpoint to split the data sequence, the previous part and the back part of the similar quicksort, so as to complete the rapid sorting of all data series, and finally turn this data series into an ordered sequence, according to this idea for the above array a of the whole process of quick sorting is shown in Figure 6:

    Initial state. After a quick sort, it's divided into 49

    The two parts are quickly sorted separately, and after the third and fourth steps are exchanged, they become completed sorts.

    76 97 65} After the third and fourth steps are swapped, it becomes Complete Sorting.

Related questions
6 answers2024-04-08

How it works: Divide the array into two sides so that the numbers on the left are always smaller than those on the right, and then sort them separately (like divide and conquer). >>>More

4 answers2024-04-08

SEO fast ranking technology is simply put: it is to brush traffic through software clicks, brush external links (do black chains, just like cheating in exams), so that the **ranking increases, but the ranking will decline in a few months optimized by fast ranking technology

4 answers2024-04-08

The Pascal compilation system is a system software. Pascal is the first structured programming language with rigorous syntax, clear hierarchy, easy to write and readable programs. Pascal language is widely used in various software, and the program is divided into name (self-proposed after program), setting (defined after var), start (begin), program (body), read (read read ln), and end (end), with strong structural hierarchy, rigorous and tight. >>>More

3 answers2024-04-08

1.Strings are used to store entire batches of character data. Strings are commonly used in programming to store characterized numeric data. >>>More

15 answers2024-04-08

First, the bubbling method sorting.

for i:=1 to n-1 do >>>More