Selection of the linear structure Problem -ReversingLinkedList

Newer and more comprehensive "data structures and algorithms," the update site, more python, go, waiting for you teaching artificial intelligence: https://www.cnblogs.com/nickchen121/p/11407287.html

First, what is an abstract list

  • A block of local storage data
  • The next node address - at the local store pointer block

Second, the reversal of a single list

/* c语言实现 */

Ptr Reverse(Ptr head, int K)
{
  cnt = 1;
  new = head->next;
  old = new->next;
  while (cnt < K) {
    tmp = old->next;
    old->next = new;
    new = old; old = tmp;
    cnt++;
  }
  head->next->next = old;
  return new;
}

Tricky: a table storing the order, first order, and then directly output in reverse order.

The above tricks solution: pay more nodes a few useless in memory.

Third, the test data

In the pat testing , the test data of this question mainly concerns the following points:

  • There is not inverted tail
  • Extra nodes

3.1 Limit Testing

  • Taken to address the bounds
  • Just reverse the whole
  • K = N complete inversion
  • K = 1 without reverse
  • Maximum (K-1 finally left not reversed), the minimum N

Guess you like

Origin www.cnblogs.com/nickchen121/p/11562533.html