Can anybody finds the mistake i did in this code? | Sololearn: Learn to code for FREE!
+ 2

Can anybody finds the mistake i did in this code?

I am trying to create two different Linkedlist using one program. https://code.sololearn.com/cbiocIBOxLTg/?ref=app

9th Oct 2022, 6:04 AM
Rajeev Sharma
Rajeev Sharma - avatar
2 Answers
+ 1
llist1 and llist2 contains so called garbage data if you dont init them and, because of that, at first insert, the program try to dereferenciate pointer (next node) that point to not allocated memory obtaining a segmentation fault. You have to init either with manual init or with the getNewNode funcion. P.S. Dont forget to implement code for deallocation
9th Oct 2022, 7:19 AM
KrOW
KrOW - avatar
+ 1
Read the comments of following edited code https://www.sololearn.com/compiler-playground/cN9POa7pjj7p/#c I would like add to hints. 1) Start to handle memory deallocation too 2) Your would better compoisiting a List data structure adding a List structure that contains a pointer to first node and add functions on manage the nodes
9th Oct 2022, 1:54 PM
KrOW
KrOW - avatar