I agree with @JS1's comments. I'd add a few others.
- You could consider replacing your
while
loops with function calls. This could increase readability somewhat and eliminate the need for commenting at all, if you have nice function names. This would make your code more compact, though arguably slow it down since now you've got a function call. However, there are some C compile options that would support inline-ing a function some C compile options that would support inline-ing a function. - The more succinct a comment is, the more likely it is to be read. Even if you don't make new functions, I'd recommend shortening your comments. For example, I'd probably shorten:
// now we look for n node, cur is currently pointing to node after m, prev points to node before // we will reverse links as we go and after loop cur will point to n node
to:
// count to the nth code
// reverse links during traversal
Some of your naming could be more descriptive. For example, you could rename
count
toposition_indicator
since you are really tracking position rather than a count.Reduce repetitive code. In particular, you could move these two statements out of the
if...else
branch at the end of your function since you write the identical statement in each branch right now:cur->next = prev; m_node->next = after_n_node;
I agree with @JS1's comments. I'd add a few others.
- You could consider replacing your
while
loops with function calls. This could increase readability somewhat and eliminate the need for commenting at all, if you have nice function names. This would make your code more compact, though arguably slow it down since now you've got a function call. However, there are some C compile options that would support inline-ing a function. - The more succinct a comment is, the more likely it is to be read. Even if you don't make new functions, I'd recommend shortening your comments. For example, I'd probably shorten:
// now we look for n node, cur is currently pointing to node after m, prev points to node before // we will reverse links as we go and after loop cur will point to n node
to:
// count to the nth code
// reverse links during traversal
Some of your naming could be more descriptive. For example, you could rename
count
toposition_indicator
since you are really tracking position rather than a count.Reduce repetitive code. In particular, you could move these two statements out of the
if...else
branch at the end of your function since you write the identical statement in each branch right now:cur->next = prev; m_node->next = after_n_node;
I agree with @JS1's comments. I'd add a few others.
- You could consider replacing your
while
loops with function calls. This could increase readability somewhat and eliminate the need for commenting at all, if you have nice function names. This would make your code more compact, though arguably slow it down since now you've got a function call. However, there are some C compile options that would support inline-ing a function. - The more succinct a comment is, the more likely it is to be read. Even if you don't make new functions, I'd recommend shortening your comments. For example, I'd probably shorten:
// now we look for n node, cur is currently pointing to node after m, prev points to node before // we will reverse links as we go and after loop cur will point to n node
to:
// count to the nth code
// reverse links during traversal
Some of your naming could be more descriptive. For example, you could rename
count
toposition_indicator
since you are really tracking position rather than a count.Reduce repetitive code. In particular, you could move these two statements out of the
if...else
branch at the end of your function since you write the identical statement in each branch right now:cur->next = prev; m_node->next = after_n_node;
I agree with @JS1's comments. I'd add a few others.
- You could consider replacing your
while
loops with function calls. This could increase readability somewhat and eliminate the need for commenting at all, if you have nice function names. This would make your code more compact, though arguably slow it down since now you've got a function call. However, there are some C compile options that would support inline-ing a function. - The more succinct a comment is, the more likely it is to be read. Even if you don't make new functions, I'd recommend shortening your comments. For example, I'd probably shorten:
// now we look for n node, cur is currently pointing to node after m, prev points to node before // we will reverse links as we go and after loop cur will point to n node
to:
// count to the nth code
// reverse links during traversal
Some of your naming could be more descriptive. For example, you could rename
count
toposition_indicator
since you are really tracking position rather than a count.Reduce repetitive code. In particular, you could move these two statements out of the
if...else
branch at the end of your function since you write the identical statement in each branch right now:cur->next = prev; m_node->next = after_n_node;