0

How can I do this recursive?

I want to change this method from iterative to recursive public Object elimina(){ if(a == -1){ sout(“cola vacía”); return null; } else { Object aux = cola[0]; for(int i = 0; i < a; i++){ cola[i] = cola[i + 1]; } a- -; return aux; } } I tried this public Object elimina(int i){ if(a == -1){ sout(“cola vacía”); return null; } else { Object aux = cola[0]; if(i < a){ cola[i] = cola[i + 1]; elimina(i + 1); } a- -; return aux; } }

26th Jan 2021, 10:03 PM
Diego Becerril
Diego Becerril - avatar
9 Answers
0
just practice, to know more about how recursivity works, but i’ve got stuck here in this problem, could you help me? :)
27th Jan 2021, 3:28 AM
Diego Becerril
Diego Becerril - avatar
0
Abol the context is that im doing a static queue, the for just travel the whole queue to delete the first one. for example I queue the numbers 1,2,3,4 and 5. following the queue concept the first i have to unqueue is the 1, wich my program do, but it also get a null and the sout(pila vacia)
27th Jan 2021, 3:49 AM
Diego Becerril
Diego Becerril - avatar
0
sorry for not explainig haha, sout means System.out.println();
27th Jan 2021, 5:04 AM
Diego Becerril
Diego Becerril - avatar
0
yeah it worked! thank you so much! đŸ€©
27th Jan 2021, 5:10 AM
Diego Becerril
Diego Becerril - avatar