I'm just getting into TCO and I understand the concept of how it reuses a single stack frame rather than creating a new one each time the method calls itself. I intuitively want to compare this structure to a
while loop as the loop will continually perform an operation on a set of variables until the condition isn't met.
However, given that TCO uses only one stack frame it seems like performing a sorting algorithm such as quicksort wouldn't be possible using TCO as a reference to the stack frames would be needed once the recursive method "unwinds" back up the call stack once the base case is reached. Without a reference to the number of times the method was called, how does it know which subsequent operation to perform and how many times to perform it?
Given the method body for each call is the same I guess it could just keep a reference to the number of times the method has been called and then a pointer inside the method body of where to start execution but that's just a guess.
Thanks for your help.