【发布时间】:2015-09-26 22:44:14
【问题描述】:
#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;
}
在上面的代码中,我收到以下错误。
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]);
^
你能弄清楚错误是什么吗?而且我想知道为什么我只在数组l 而不是r 或c 中收到此错误。所以也请解释一下。
这是上面程序的链接。
【问题讨论】:
-
i,1,l,I,|,j- 你就是这么爱你的读者吗? :-) -
这是一个混淆代码的挑战吗?
标签: c++ c arrays parameter-passing quicksort