![]() |
Need urgent help in linked list
I encounter some problem in linked list coding. I extarcted part of the coding from a C++ book and I have been studied it for so long but still cant fix the error.
The error is the variable "counter". In the book, "counter" is the variable to store the number of elements in the linked list and it's defined in private part of the class. In the constructor, they let counter=0 where the compiler shows that it's an error. Another errors are all the "counter++" in "insert2". I tried to correct those errors but i just can't fix them... Below are my coding. I'm struggling in this coding and i hope someone can help me... :nonod: Code:
#include <iostream> |
Re: Need urgent help in linked list
There are lots of code related to linked list and searching can help you a lot
|
Re: Need urgent help in linked list
hi,
actually other templates and the main body is functioning well, only the template for "insert2", that is inserting a node into a particular position in the linked list. I have no choice but to use this function as i'm required to do so.. Is there any recommandation for it? |
Re: Need urgent help in linked list
What exactly is the problem?
Are you getting compile-time errors, and if so what are they? If I complie the code I get "'counter' : undeclared identifier" in linkedList::linkedList(), which is correct as there is no such variable linkedList::counter. Look carefully at the linkedlist class definition and you'll see the problem. If you can't, then tell me where you think linkedList::counter is defined (give the surrounding lines for context rather than line numbers). By the way, there's a good reason to use indenting correctly. Fix that and all sorts of problems will become immediately apparent, including I think this one. Has the inaccurate indentation of linkedlist::node::counter fooled you? |
| All times are GMT +5.5. The time now is 11:57. |