Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

I agree with @JS1's comments. I'd add a few others.

// 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 to position_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 to position_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 to position_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;

Source Link
sunny
  • 1.9k
  • 1
  • 13
  • 29

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 to position_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;

lang-c

AltStyle によって変換されたページ (->オリジナル) /