Yeah, i see that. Here isn't 9am on a tuesday morning but midnight wednesday. And after deleting that line, code didn't debug at all.
My problem is, the function for deleting isn't working at all. All it does is juts break and that's all. Why is that? Will you please help me and guide me? Thanks a lot.
This is probably because you are attempting to delete a value you that isn't in the list which will cause an access violation. You should try adding '5' to the list and then deleting '5' and it should work fine.
If you don't want the program to crash when a value is entered that is not in the list, I would highly suggest using a try catch block to catch an exception. A nice tutorial on how to add try catch blocks to your program can be found here:
I mean when you run the program you should be shown 5 options:
1. Add
2. Display
3. Insert
4. Delete
0. Exit
You will need to either select the "Add" or "Insert" option before attempting to delete a value from the list, as nothing exists in the list when the program initially starts.
Ah, so you mean when one inputs data, the inputted isn't accepted or isn't saved? Something like that, you mean? How do i change that? What should i change, arrange, delete or add to my code? Please suggest what you think should be. Guide me please thanks.
I am getting the feeling that you have not programming a single line of the code above. I would suggest looking at some C++ tutorials to further your knowledge in linked lists and C++ in general.
So now, you get the feeling that I didn't code any of the codes' lines? If that is your choice, well then do so, I won't stop you really. I need not to look at some C++ tuts because I have done them so, before asking here in this forum. It seems like this isn't of any help, might as want to look others now. Thanks for your time dude. I was asking for your help to guide me to what you were saying but then this? Thanks alot.
Just wrote a big write up here but then realized something that is probably causing most of your frustration. You never check to make sure the current pointer isn't null before you access a pointer in the struct. Almost guaranteed to get a seg fault or access violation at some point if you don't error check for a null pointer. It's probably the most frustrating thing to learn when dealing with pointers in C/C++ and something that pretty much all C/C++ programmers struggle with initially.
Example, you do check for the current pointer to be null in your loop, but then you proceed to do q->next->data. If q is not null the loop will engage, but if the child is null, this will result in a seg fault/access violation (depending on compiler). Always check for null before accessing a member within a struct, and you have to treat internal pointers to the same type of struct as it's own struct.
I'm assuming this project forbids using an OOP approach or the class is pre-OOP, otherwise this whole design should be scrapped for an object based solution.