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

30th Jan 2021, 1:08 AM
Diego Becerril
Diego Becerril - avatar
9 Respostas
+ 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)
30th Jan 2021, 2:37 AM
durian
durian - avatar
+ 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
30th Jan 2021, 2:06 AM
durian
durian - avatar
+ 1
And how can i solve it?
30th Jan 2021, 2:10 AM
Diego Becerril
Diego Becerril - avatar
+ 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
30th Jan 2021, 2:16 AM
durian
durian - avatar
+ 1
woooow thaaaanks! its perfect! thank you so much
30th Jan 2021, 2:48 AM
Diego Becerril
Diego Becerril - avatar
0
you modified the queue method?
30th Jan 2021, 2:21 AM
Diego Becerril
Diego Becerril - avatar
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
30th Jan 2021, 2:27 AM
durian
durian - avatar
0
yea I see, but how can i do it withour recursion? or without modifying the queue method?
30th Jan 2021, 2:32 AM
Diego Becerril
Diego Becerril - avatar
0
👍
30th Jan 2021, 2:50 AM
durian
durian - avatar