//输出单链表倒数第k个结点
struct int_List_Node{
int value;
struct int_List_Node *next;
};
int count_back_k( const struct int_List_Node * L , const int k ) {
struct int_List_Node *p = L;
struct int_List_Node *q = L;
int m = k;
while( ( m -- ) && ( p != NULL ) ) {
p = p -> next;
}
if( m > 0 ) {
cout << "error";
return -1;
}
while( ( p != NULL ) && ( q != NULL ) ) {
p = p -> next;
q = q -> next;
}
return q -> value;
}
输出单链表倒数第k个结点
最新推荐文章于 2022-09-24 20:21:05 发布