-1

sorry for avoiding you guys

i have a problem with reverse function in circular linked list.

void reverse() {
    int num = many;
    node* current = head;
    node* previous = 0;
    while (num != 0) {
        cout << "1" << '\t';
        node* r = previous;
        previous = current;
        current = current->next;
        previous->next = r;
        num--;
    }
    head = previous;
}

in this func after 2 while sentence

problem comes up in line that current = current->next;

(exception throw : read access violation, current was 0xDDDDDDDD)

how to handle it??

임도경
  • 41
  • 1
  • 5

1 Answers1

0

This is from Visual Studio trying to help you (and succeeding, IMO).

As Mark Ingraham pointed out in another answer a long time ago, Visual Studio's runtime library will fill a block of data with 0xDDDDDDDD when you release a block of heap memory.

So, although you haven't shown any code that's deleting from your list, if there is such code, that's probably the first place to look--at least at first glance, it looks like there's a fair chance that when you try erase a node from the list, you're deleting the memory the node lives in, but still leaving a pointer to that deleted memory.

It's also possible (but less likely, IMO) that you're just using memory without initializing it--and you happen to be hitting a block of memory that was previously allocated and then released back to the heap manager.

The bottom line, however, is that you don't "handle" the access violation. Instead, you need to find the bug in your code that's leading to the access violation happening, and fix it so that doesn't happen any more.

Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111