当我们不知道链表的大小并且必须仅使用一个循环和一个指针执行时,如何找到链表的中间点。
最佳答案
怎么样
LinkedList * llist = getLList(); // the linked list
Node * node = llist.head;
while ( node ) {
node = node.next;
if ( node ) {
node = node.next;
llist.remove( llist.head );
}
}
// now llist.head is (er, um... was) the middle node.
// hope you didn't need the rest of the list.
关于c++ - 链表的中间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1746594/