我无法在 C 中反转我的双链双端队列列表(只有一个后哨),我正在通过切换指针来接近它,这是我到目前为止的代码:
/* 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 这个过程似乎弄乱了数字的实际值。IE。2变成2.90085e-309...我认为指针切换搞砸了,但我找不到问题。即使这并不意味着我的代码是正确的;它编译得很好。