Hi guys, I am trying to implement an ADT list, but when I compile it, it freezes and the following message appears:
"xxx.exe has encountered a problem and needs to close. We are sorry for the inconvenience."
At the moment I am using Dev-C++ 4.9.8.0, and I am not sure if the compiler is responsible for this error.I know its not the best choice, but I dont have another at this computer at the moment.
tried it on Dev-C++ 4.9.9.2 and I'm not getting that error message. It crashes after printing though, and the first character prints out wrong too. I hope that helps. :P
I get the same error.It prints several characters and then freezes.I am trying to understand the concept of List ADT.Here is another code, but I don't know how to fill that list.I will be very thankful if you help me, because, apparently, I cant do it by myself, and it drives me crazy :))
well when the program crashes it usually is because of pointers. Most likely trying to access a bad pointer. Your code is quite long so I'll have to take a good look at it first. =)
well, I think the insertAfter method is what you need to use to insert nodes into the list.
However i don't quite see how to get the first position to insert to which is a parameter in the insertAfter method. Even though there is a first and before method that returns a position, since the list will start out empty it just ends up throwing an exception. Did you make the NodeList class?
I still can't quite figure it out, maybe I need to get some sleep first it's 5:48 am here in my timezone. I'll try again when I wake up though.
Nope it's not really a mistake that the Position class is public, I thought it was protected or private though because normally public members break encapsulation. I still can't figure it out at the moment though, I haven't been programming in C++ for a while so I'm a bit rusty on the syntax and such. :P
I also noticed in that class it has a method to get the previous node, but not the next node on the list. Does that mean the list should be traversed backwards?
I'm back, I figured out how to access the Position class but trying to construct a Position object just gives a null NodePtr though, and you can't pass in a NodePtr object cause the Node structure is protected. Maybe this class was meant to be subclassed?
Still confused how to get the head NodePtr Position so we can start inserting nodes, but I'm still working on it. =)
By the way, what about insertFirst function used for lists, I read somewhere something about it a few months ago, but I am not sure if I can implement it, but I am pretty sure that we should use it.I will search for more info in uncle google :))
lolz i find it a lot easier making lists from scratch actually. Trying to figure out what someone was trying to do is sometimes more difficult in my opinion. I think the easy way to make it work would be to add an accessor method so we can get access to the head node of the list and pass it to the Position constructor to create a valid position. Once we have a valid Position object we can just use the insertAfter method to insert nodes into the list.
Anyways you can always email me if you find anything interesting about the insertFirst function. My email is [email protected].
I'll try adding an accessor method and post what I have here, or I could email it to you which would be probably easier. :P
Anyways here's the result, it's actually very simple once you have access to the head node pointer. I really wanted to understand how the person who created the class want us to use his class instead of introducing a method which bypasses the actual design. It's most likely done through inheritance I think, but I haven't been programming in C++ for a while so I'll need to review and get some practice on that again I think. =)