c++ - error: invalid types 'int[int]' for array subscript -
#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; }
in above code getting following error.
prog.cpp: in function 'int pivot(int, int)': prog.cpp:21:13: error: invalid types 'int[int]' array subscript swap(&l[i],&l[j]); ^ prog.cpp:21:19: error: invalid types 'int[int]' array subscript swap(&l[i],&l[j]); ^ prog.cpp:26:11: error: invalid types 'int[int]' array subscript swap(&l[h],&l[j+1]); ^ prog.cpp:26:19: error: invalid types 'int[int]' array subscript swap(&l[h],&l[j+1]); ^
can figure out error is? , wondering why getting error in array l
not in r
or c
. please explain also.
here link of above program.
l
function parameter of type int
, hides global variable same name.
Comments
Post a Comment