TriMickTri / elements-of-programming-interviews

Automatically exported from code.google.com/p/elements-of-programming-interviews
Other
0 stars 0 forks source link

Patch for /trunk/Remove_kth_last_list_template.cpp #13

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
1->3->5->7->9    suppose we need to delete  4th element from last i.e '3'  and 
num = 4 initially. after the first while loop, ahead will be at 9 and num will 
be -1 due to which it will enter the if condition and throw exception.

Original issue reported on code.google.com by arunsiva...@gmail.com on 24 Jul 2013 at 6:09

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
The other way is changing the first while loop.

while( front && num){
      ahead = ahead -> next;
      num = num -1;
}

Original comment by arunsiva...@gmail.com on 25 Jul 2013 at 4:23

GoogleCodeExporter commented 9 years ago
Hey Arun,

Thanks for your report, and it is really a good catch! I have fixed this and 
push it.

Original comment by TsungHsi...@gmail.com on 30 Jul 2013 at 8:39