Anu*_*arg -4 c c++ arrays parameter-passing quicksort
#include <iostream>
using namespace std;
int t,n,k,m,i,j;
int l[100002],r[100002],c[100002],a[100002],total=0;
int swap( int *a, int *b)
{
int temp=*a;
*a=*b;
*b=temp;
}
int pivot( int l, int h)
{
int x=c[h],i=l,j=l-1,temp;
for(i=l;i<h;i++)
{
if(c[i]<x)
{
j++;
swap(&c[i],&c[j]);
swap(&r[i],&r[j]);
swap(&l[i],&l[j]);
}
}
j++;
swap(&c[h],&c[j]);
swap(&l[h],&l[j+1]);
swap(&r[h],&r[j+1]);
return j;
}
int quick( int l, int h)
{
int p;
if(l<h)
{
p=pivot(l,h);
quick(l,p-1);
quick(p+1,h);
}
}
int main() {
cin>>t;
while(t--)
{
total=0;
cin>>n>>k>>m;
for(i=1;i<=n;i++)
{
cin>>a[i];
total+=a[i];
}
for(i=1;i<=m;i++)
cin>>l[i]>>r[i]>>c[i];
quick(1,m);
for(i=1;i<=m;i++)
cout<<l[i]<<r[i]<<c[i]<<endl;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在上面的代码中我收到以下错误.
prog.cpp: In function 'int pivot(int, int)':
prog.cpp:21:13: error: invalid types 'int[int]' for array subscript
swap(&l[i],&l[j]);
^
prog.cpp:21:19: error: invalid types 'int[int]' for array subscript
swap(&l[i],&l[j]);
^
prog.cpp:26:11: error: invalid types 'int[int]' for array subscript
swap(&l[h],&l[j+1]);
^
prog.cpp:26:19: error: invalid types 'int[int]' for array subscript
swap(&l[h],&l[j+1]);
^
Run Code Online (Sandbox Code Playgroud)
你能弄清楚错误是什么吗?而且我想知道为什么我只在数组中得到此错误l而不是r或c.所以请解释一下.
这是上述程序的链接.