
今后,动力节点Java学院将每天为大家带来一道大厂面试真题,这些面试题都是大厂技术专家们结合多年的工作、面试经验总结提炼而成的面试真题。
通过这些面试题,还可以间接地了解技术大牛们出题思路与考察要点。建议大家收藏并分享给更多需要的人。
问:如何实现一个高效的单向链表逆序输出?——阿里巴巴出题专家:昀龙/阿里云弹性人工智能负责人参考答案下面是其中一种写法,也可以有不同的写法,比如递归等。供参考。 typedefstructnode { intdata; structnode*next; node(intd):data(d),next(NULL){} }node; voidreverse(node*head) { if(NULL==head||NULL==head->next) { return; } node*prev=NULL; node*pcur=head->next; node*next; while(pcur!=NULL) { if(pcur->next==NULL) { pcur->next=prev; break; } next=pcur->next; pcur->next=prev; prev=pcur; pcur=next; } head->next=pcur; node*tmp=head->next; while(tmp!=NULL) { cout<data<<"\t"; tmp=tmp->next; } }
宅在家里,我是这样赶超别人的