Category : linked-list

I’m getting run time error and I don’t know why. I tried backtracking but couldn’t figure out. please help! ================================================================= ==31==ERROR: AddressSanitizer: heap-use-after-free on address 0x602000000098 at pc 0x000000370bdd bp 0x7ffdce3742a0 sp 0x7ffdce374298 READ of size 8 at 0x602000000098 thread T0 #2 0x7fe06dce80b2 (/lib/x86_64-linux-gnu/libc.so.6+0x270b2) 0x602000000098 is located 8 bytes inside of 16-byte region [0x602000000090,0x6020000000a0) freed ..

Read more

struct SinglyLinkedListNode{ int data; SinglyLinkedListNode* next = NULL; }; SinglyLinkedListNode* init(int data){ SinglyLinkedListNode *newNode = (SinglyLinkedListNode*)malloc(sizeof(SinglyLinkedListNode)); newNode -> data = data; **Line 1** newNode -> next = NULL; return newNode; } If I do not specify next of new Node "NULL" then I am getting error of infinite loop, why is that so. Isn’t NULL ..

Read more

I am trying to solve this question, where we have to reverse a doubly linked list. I have written the following function for that purpose Node* reverseDLL(Node * head) { Node *curr=head; Node *prev=curr->prev; Node *next; while(curr!=NULL) { next=curr->next; curr->next=prev; curr->prev=curr->next; prev=curr; curr=next; } head=prev; return head; } But according to the online judge, it ..

Read more