假設有3個指標:
head指向linked list頭,
cur指向linked list頭,
nextprocess指向null.
if ( cur->next->next != null ) {
cur->next->next = nextprocess;
// 將第三個node先用nextprocess指著
cur->next->next = cur;
head = cur->next;
cur->next = null;
do {
cur = nextprocess;
if ( nextprocess->next != null ) {
nextprocess = nextprocess->next;
// 檢查是否後面還有node
} // if
cur->next = head;
head = cur;
} while ( nextprocess != null )
} // if
else {
//此linked list可能只有0-2個node
} // else
沒有留言:
張貼留言