方法一:利用兩個(gè)指針p,q,首先將q往鏈表尾部移動(dòng)n位,然后再將p、q一起往后移,那么當(dāng)q達(dá)到鏈表尾部時(shí),p即指向鏈表的倒數(shù)第n個(gè)節(jié)點(diǎn)。 復(fù)制代碼代碼如下: node* find_nth_to_last(node* head,int n) { if(head==NULL || n<1) return NULL; node*p,*q; p=q=head; while(q!=NULL && n--){ q...
www.dbjr.com.cn/article/431...htm 2025-5-25