Problem list (6) - list of the return position of the reciprocal number value of k

1  / * list of the return position of the reciprocal number value of k * / 
2  / * 
3      ALGORITHM: first obtain the length len of the list, the location after acquiring the value of the element of the len-k + 1
 . 4  * / 
. 5 elemType Getelem_rear (LinkList L, int K)
 . 6  {
 . 7      IF (K < 0 )
 . 8          return  0 ;
 . 9      int len = getLength (L);
 10      int I = len - K + . 1 ;
 . 11      LNode * P = L;
 12 is      the while (I =! 0 )
 13 is      {
 14          P = p->Next;
 15          i-- ;
 16      }
 . 17      COUT << " penultimate " << << K " value of the position number is: " << p-> Data << endl;
 18 is      return p-> Data;
 . 19 }

 

Guess you like

Origin www.cnblogs.com/KBryant/p/11649941.html