Exemple #1
0
int qusort(int s[], int start, int end)
{
	int i, j;
	i = start;/* 将每组首个元素赋值给i  */
	j = end;/* 	将每组末尾元素赋值给j  */
	s[0] = s[start];/* 设置基准值 */
	while(i < j)
	{
		while(i < j && s[0] < s[j]) j--;/* 位置左移 */
		if (i < j)
		{
			s[i] = s[j];
			i++;
		}
		while(i < j && s[i] <= s[0]) i++;
		if (i<j)
		{
			s[j] = s[i];
			j--;
		}
		s[i] = s[0];
		if (start < i)
		{
			qusort(s, start, j - 1);
		}
		if (i < end)
		{
			qusort(s, j + 1, end);
		}
	}

	return 0;
}
Exemple #2
0
Fichier : 22.c Projet : shixv/test
void qusort(int *s,int start,int end)
{
    int i,j;
    i=start;
    j=end;
    s[0]=s[start];
    while(i<j)
    {
        while(i<j&&s[0]<s[j])
            j--;
        if(i<j)
        {
            s[i]=s[j];
            i++;
        }
        while(i<j&&s[i]<=s[0])
            i++;
        if(i<j)
        {
            s[j]=s[i];
            j--;
        }
    }
    s[i]=s[0];
    if(start<i)
        qusort(s,start,j-1);
    if(i<end)
        qusort(s,j+1,end);
}
Exemple #3
0
Fichier : 22.c Projet : shixv/test
int main(void)
{
    int a[]= {
        7,9,8,7,6,5,4,3,2,1,0
    };
    qusort(a,1,10);
    for(int i=1; i<11; i++)
        printf("%d ",a[i]);
    putchar('\n');
    return 0;
}
Exemple #4
0
int main(int argc, char *argv[])
{
	int a[11], i;
	printf("请输入10个整数\n");
	for (i = 0; i < 10; i++)
	{
		scanf("%d",&a[i]);
	}
	qusort(a, 1, 10);
	printf("排序后:\n");
	for (i = 0; i < 10; i++)
	{
		printf("%d ",a[i]);
	}
	putchar(10);
	return 0;
}
Exemple #5
0
/* Pre: per is a permutation of powers of 2;
 * Return the port permutation of cell a */
Intstack permuteCell(Intstack a, Intstack per) {
	Intstack result = newIntstack(a->size, NULL) ;
	int i, j, x, y;
	for (i = 0; i < a->size; i++) {
		x = a->it[i];
		y = 0;
		j = 0;
		while (x > 0) {
			y += (x % 2) * per->it[j];
			x /= 2;
			j++;
		}
		putint(y, result) ;
	}
	qusort(result->it, 0, result->size) ;
	return result;
}
int main ()
{
	cricketer *p[20];
	int i,num;
	printf("Enter the number of cricketers \n ");
	scanf("%d",&num);
	for( i=0;i<num;i++)
	{
		p[i]=(cricketer*)malloc(sizeof(cricketer));
		printf("Enter name --> ");
		scanf("%s",p[i]->name);
		//printf("Enter the age --> ");
		//scanf("%d",&p[i]->age);
		//printf("Enter the number of matches --> " );
		//scanf ("%d",&p[i]->matches);
		printf("Enter the average -->");
		scanf("%f",&p[i]->average);
	
	}
	qusort(p,num);

	return 0;
}