To be a better coder
分类: LINUX
2019-08-26 17:04:23
链表创建遍历插入删除 reverse1(node * head) { node*p,*q,*r; if( head != NULL ) { p = head; q = head->next; head->next = NULL; while(q){ r = q->next; q->next = p; p = q; q = r; } head=p; } return head; } 链表是否成环:龟兔赛跑,兔跳两格,龟爬一格,兔子为空,必不成环,相遇则成环。 while(fastPointer != null && fastPointer.next != null) { slowPointer = slowPointer.next; fastPointer = fastPointer.next.next; //两指针相遇则有环 if(slowPointer == fastPointer) { return true; } }