C语言快速排序法,急

来源:百度知道 编辑:UC知道 时间:2024/09/23 13:18:53
Description

There is a database,partychen want you to sort the database’s data in the order from the least up to the greatest element,then do the query: "Which element is i-th by its value?"- with i being a natural number in a range from 1 to N.

It should be able to process quickly queries like this.

Input

The standard input of the problem consists of two parts. At first, a database is written, and then there's a sequence of queries. The format of database is very simple: in the first line there's a number N (1<=N<=100000), in the next N lines there are numbers of the database one in each line in an arbitrary order. A sequence of queries is written simply as well: in the first line of the sequence a number of queries K (1 <= K <= 100) is written, and in the next K lines there are queries one in each line. The query "Which element is i-th by its value?" is coded by the number i.

Output

这个?? 英语我也差,看不懂啊,不过C的快速排序还是不难的啊。方法是:
定义两个变量 p,q分别指向第一个和最后一个数据。然后定义个变量ch来存中间变量。第一次:你固定最后一个不懂,将第一个数据放入ch中,然后移动p
如果p指向的数据大于q指向的数据,就将p的数据赋值给q,然后p不动,q在向前移动,找到小于p的值,就将q的值赋给p然后q不动,p在移动,直到p=q为止
然后将ch赋给最后的那个p或q。然后在进行递归调用本身。在一次比较。