我很難在C中反轉我的雙鏈接deque list(只有後哨兵),我正在通過切換指針來接近它,這裏是我迄今爲止的代碼:在C中反向雙鏈接Deque
/* Reverse the deque
param: q pointer to the deque
pre: q is not null and q is not empty
post: the deque is reversed
*/
/* reverseCirListDeque */
void reverseCirListDeque(struct cirListDeque *q)
{
struct DLink *back = q->backSentinel;
struct DLink *second = q->backSentinel->prev;
struct DLink *third = q->backSentinel->next;
while (second != q->backSentinel->next){
back->next = second;
third = back->prev;
back->next->prev = back;
back = second;
second = third;
}
}
但它似乎沒有工作,我一直在用雙端隊列,看起來像這樣測試它:1,2,3 輸出爲:3這個過程似乎搞亂實際值的數字。即。 2變爲2.90085e-309 ...我認爲指針切換已經搞亂了,但我找不到問題。即使這並不意味着我的代碼是正確的,它編譯得很好。
如果這是一項家庭作業,您應該爲您的問題添加_homework_標籤。 – zneak 2010-07-20 03:26:15