Reversing a circular deque without a sentinel
Posted
by SDLFunTimes
on Stack Overflow
See other posts from Stack Overflow
or by SDLFunTimes
Published on 2010-04-30T20:14:13Z
Indexed on
2010/04/30
20:17 UTC
Read the original article
Hit count: 282
Hey Stackoverflow I'm working on my homework and I'm trying to reverse a circular-linked deque without a sentinel. Here are my data structures:
struct DLink {
TYPE value;
struct DLink * next;
struct DLink * prev;
};
struct cirListDeque {
int size;
struct DLink *back;
};
Here's my approach to reversing the deque:
void reverseCirListDeque(struct cirListDeque* q) {
struct DLink* current;
struct DLink* temp;
temp = q->back->next;
q->back->next = q->back->prev;
q->back->prev = temp;
current = q->back->next;
while(current != q->back->next) {
temp = current->next;
current->next = current->prev;
current->prev = temp;
current = current->next;
}
}
However when I run it and put values 1, 2 and 3 on it (TYPE is just a alias for int in this case) and reverse it I get 2, 3, null. Does anyone have any ideas as to what I may be doing wrong?
Thanks in advance.
© Stack Overflow or respective owner