If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

There were 22 unique 5-digit integers in the file.
The highest unique count in one list was 6 integers.

My code that will follow soon displays/prints only the LAST 5-digits "group" of integers (in this case the 5-digits starting with 3). I am not sure what's wrong with my code; perhaps I am not designing it correctly. May be my calls in it are on the wrong place or I have to write all integers and then traverse it and output it (if that's the case, I am not sure how).

Re: HELP Implementing Double Linked Lists as an Array of Pointers in C++

Originally Posted by lanza

I am not sure what's wrong with my code; perhaps I am not designing it correctly. May be my calls in it are on the wrong place or I have to write all integers and then traverse it and output it (if that's the case, I am not sure how).

Honestly, there should be no "maybes" when you write the code. Everything you code must be done with certainty that what you have written will execute properly. Everything you design must be done with complete confidence that the design works -- first on paper, and then translated to programming code.

Of course, if the code doesn't execute properly (which is more often than not), then you debug the code using the debugger or whatever other technique (print statements, etc.) to find out where the code deviates from your initial plans. Then you fix the code according to what you've discovered by debugging, or you redo your design based on what you've discovered by debugging. That is how programming works, whether it is student or professional.

Re: HELP Implementing Double Linked Lists as an Array of Pointers in C++

Hi Paul,

Big thanks for the reply.

I used the debugger and so far follows most of my design (but not sure how to display all data yet):

1) I read the data file and while it is reading it
2) check for duplicates
3) if it's not a duplicate then I will add into the lists based on the first digit
4) then I counted and display it, HOWEVER
it is displaying the last 5-digit integers (starting with digit 3) as follows:

If you claim that you don't see all your output, the only conclusion is that "p" no longer points to the beginning of your list of nodes.

This is what I mean by debugging -- somewhere along the way, you've either lost track, replaced, or did something that causes the list to either lose its contents, or you've moved the head of the list around and now it points somewhere else. How else would a seemingly simple print loop not print out the correct results, unless "beginning" has been trashed somewhere?

So use the debugger, keep track to make sure what is happening to "beginning" to see where it goes wrong.

Re: HELP Implementing Double Linked Lists as an Array of Pointers in C++

Topic number 1 in schools really should be how to use the debugger and why you can't write any code without it. You've made the classic beginner mistake of trying to write the whole program at once and now you have to figure out which part is broken. Any of us would write one small part at a time, step through it in the debugger to make sure it's doing what we want it to, then moving on to the next part. What you need to do now is step through all your code. Make sure the nodes are being created and inserted correctly, make sure you dupe test is working correctly, then make sure you're outputting correctly. Your mistake could be anywhere. You need to debug individual functions as you go so that when something goes wrong, it's pretty easy to identify.

Re: HELP Implementing Double Linked Lists as an Array of Pointers in C++

Big Thanks for all of you.

Problem solved; now I just need to figure out how this program will produce the last line of the sample output such as "The highest unique count in one list was 6 integers". In other words, what list has the highest values in it.

Re: HELP Implementing Double Linked Lists as an Array of Pointers in C++

Originally Posted by GCDEF

Topic number 1 in schools really should be how to use the debugger and why you can't write any code without it.

I disagree. Real programmers don't use debuggers. They write correct code. And they use the Stepwise Refinement method to accomplish that.

Debuggers are fine when you inherit a pile of crap code and need to quickly hide the bad smell. But when you write new code it should work from start to finish and you should be confident it does.

In this case the OP should start all over and develop the code incrementally in small working steps one by one. Start with something working and make sure everything you add in works too. How hard is that really?

Re: HELP Implementing Double Linked Lists as an Array of Pointers in C++

Originally Posted by nuzzle

I disagree. Real programmers don't use debuggers. They write correct code. And they use the Stepwise Refinement method to accomplish that.

Debuggers are fine when you inherit a pile of crap code and need to quickly hide the bad smell. But when you write new code it should work from start to finish and you should be confident it does.

In this case the OP should start all over and develop the code incrementally in small working steps one by one. Start with something working and make sure everything you add in works too. How hard is that really?

Re: HELP Implementing Double Linked Lists as an Array of Pointers in C++

Originally Posted by nuzzle

No I don't.

It's much better to avoid errors than to look for them later.

I don't know of any programmers that write perfect code on the first try every time, and I don't know of any programmers that can look at code and be absolutely positive what it's doing every time. What I'm saying, is write a small section of code, run it in the debugger to be sure it works then move on to the next piece. Proper use of the debugger is the way to avoid errors.

Re: HELP Implementing Double Linked Lists as an Array of Pointers in C++

Originally Posted by nuzzle

I disagree. Real programmers don't use debuggers. They write correct code. And they use the Stepwise Refinement method to accomplish that.

Debuggers are fine when you inherit a pile of crap code and need to quickly hide the bad smell. But when you write new code it should work from start to finish and you should be confident it does.

In this case the OP should start all over and develop the code incrementally in small working steps one by one. Start with something working and make sure everything you add in works too. How hard is that really?

The best and most reliable method of achieving this "stepwise refinement" is stepping through your code in a debugger and verifying that it does indeed work as you intended.