1

This is one of those times when I would recommend starting over. Try and break it down in terms of what you need your function to do, and build some pseudocode first. Some pointers: First, recursion is a good way of solving this. But chaining two functions out of lock_pairs() is a bit redundant. Try and have just one makes_cycle(). What's the job of ...


1

I found it unnecessary to check multiple branches to the same node the way I executed my lock cycles function. I was very surprised by this. Whether this is related to the fact the graph does not have multiple sources for the purposes of this assignment, possibly.


1

rank++ This means "tell me the value of rank, then add one to rank". So in the last line of elim_test, you're calling elim_test again with the exact same values over and over again. To fix this, you can either use ++rank, which means "add one to rank, then tell me the value of rank", or you can write elim_test(voter, rank + 1);, since ...


1

The problem with using recursion here, is that it executes x times not only the part with the sorting but also the printing part. If you want to go with recursion you could split into two separate functions: the recursive one, for the sorting part, and other with the printing part. If you want to keep it in one function, you could simply change the value of ...


1

Actually, it probably leaks a lot more than that, depending on the size of the linked list. The first version is an either/or. It will either free a node or move to the next node. In practice, that means that it will walk the linked list to the last node and free it, and then return to the original calling code. The second version is different. It will ...


Only top voted, non community-wiki answers of a minimum length are eligible