Can anybody help me out yet again?? 😅 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
14th Dec 2021, 12:02 AM
Aditya
Aditya - avatar
4 Answers
+ 3
Martin Taylor It's a common University problem :) We're taught this way. Main Answer: Most problems were - 1. Segmentation fault - because of "illegally" accessing a node. Imagine if node->prev is NULL, you can't access it's next right? :) so a check like if(node->prev) should be added. Same with some checks in HEAD == NULL 2. Not stopping the function since you've now added checks if (HEAD==NULL) but does that stop the execution of code after if statement? Nope. So, either add a "return;" as I've done or use else {} block for the remaining part 3. Since in some functions (push and append), there's a possibility of Manipulating the real HEAD pointer itself (like when it is NULL) you should send a Pointer to a Pointer (Node **) to the function and when you've to change *the real HEAD Node*, you would do it like *head = some_node And as Martin Taylor suggested, outside of your University assignments, please use the list class. https://code.sololearn.com/cZ73CDB0FlX6/?ref=app
14th Dec 2021, 5:14 AM
Nikhil
Nikhil - avatar
+ 3
Thanks Nikhil for bringing out one of the most helpful feature of sololearn i.e. community help...... 😊 you're truly uncapped heroes.. ..... 😊
14th Dec 2021, 1:57 PM
Aditya
Aditya - avatar
+ 1
Martin Taylor I get your point dear SIRE but the program was originally designed for C I'm just modifying it minimally to run as CPP
14th Dec 2021, 1:52 PM
Aditya
Aditya - avatar
0
Martin Taylor I appreciate your concern but to learn that we've to learn STL...... our course focuses on raw programming....... 😔
14th Dec 2021, 5:13 AM
Aditya
Aditya - avatar