I’ve been debugging for a few hours and I really am completely lost. Help!
NOTE: There is a lot more code than this in the program but the rest works fine so I tried to pull all relevant code. If you notice anything missing though, please let me know.
typedef struct cellT {
queueElementT value;
struct cellT *link;
} cellT;
struct queueCDT {
cellT *head;
cellT *tail;
};
void ReverseQueue(queueADT queue){
int i, x, length;
length = QueueLength(queue);
cellT *beg, *end;
queueElementT temp;
beg = queue->head;
for(i = 0; i < (length/2); i++){
end = beg;
for(x = 0; x < (length-i); x++)
end = end->link;
/* POINTERS REMAIN, VALUES SWAPPED */
temp = beg->value;
beg->value = end->value; /* gdb says issue happens here */
end->value = temp;
}
}
The problem might be this loop:
Try changing it to: