0
Unqueue a dinamic queue
I want to unqueue the other letters, but i only get the last one (like it is supposed to) but i get a pointer exception, what im doing wrong? https://code.sololearn.com/c75U07MhvUs6/?ref=app
9 Answers
+ 1
this is probably not the best implementation
if u dont want to do recursion,
then at least i think u should have a Node that points to the first node in queue
https://code.sololearn.com/cAJhtgW0ehpX/?ref=app
here i add new Node in queue(head node),
i still modified the queue and unqueue method though(just 1 line)
+ 1
Node aux = a;
a = getNext(); //this line return null
then, u try to call desp method from a null object,it will throw error
+ 1
And how can i solve it?
+ 1
i dont know if this what u want ,but to unqueue i would do something like this
https://code.sololearn.com/csaIc9e8uvS7/?ref=app
+ 1
woooow thaaaanks! its perfect! thank you so much
0
you modified the queue method?
0
yea..instead of assigning Node a to the newest node in queue, it will always be the first node in queue
then , set the next node using recursion
since unqueue will get the first node in queue, it will be easier to implement it
u just do something like this in unqueue method:
1.copy Node a to a temp Node
2.set Node a to new first node
3.return the temp Node
0
yea I see, but how can i do it withour recursion? or without modifying the queue method?
0
đ