我正在尝试将值推送到列表。我的列表位于一个包含许多列表的类中,该类包含一个函数getList(int),该函数采用一个整数并返回它表示的列表。例如getList(6)将返回列表G。包含所有列表的类称为“ z”。但是,当我尝试使用该值推送值时:z.getList(6).push(value); 它不会将其推入G。如何编写将值推入使用getter函数调用的列表的行? 我拥有的代码:
class Fila {
public:
LList a,b,c,d,e,f,g,h,i,j;
//public:
LList q;
LList getList(int n);
};
LList Fila::getList(int n) {
if(n==0){return a;}
else if(n==1){return b;}
else if(n==2){return c;}
else if(n==3){return d;}
else if(n==4){return e;}
else if(n==5){return f;}
else if(n==6){return g;}
else if(n==7){return h;}
else if(n==8){return i;}
else {return j;}
}
void radixsort(Node *front, Node *back) {
Fila z;
Node *t=front;
while(t){
z.q.push(t->data);
t=t->next;
}
for(int k=0;k<log(99)+1;k++){
while(!z.q.empty()){ //anade a los bucket
if(k==0){
for(int l=0;l<10;l++){
if((z.q.front())%10==l){
z.getList(l).push(z.q.front()); //THIS LINE
break;
}
...
改变这个
对此
Your version isn't returning the list in your class, it's returning a copy of the list in your class. By changing the
getList
function to return a reference it does return (a reference to) the list in your class.