Solved

Could someone answer my questions on this LL Header?

Posted on 2001-06-20
8
630 Views
Last Modified: 2006-11-17
I was hoping someone could answer my questions I posted for this LL header file.

I am not sure what this struct NodeType is for and why do you need it?
struct NodeType;

I am not sure what this line is doing?
typedef NodeType *NodePtr;

//Complete Declaration.
struct NodeType
{
int num2;
NodePtr link; Is link a pointer?
};
class List
{
public:
List(); //Constructor
~List(); //Destructor
bool Isempty() const;//Checks to see if Node is empty
void InsertAfter(int num);//Inserts the correct node value
void Delete(int num);//Deletes the correct Node value
void Print(ostream& Outfile) const;//Outputs the correct output
void Print1(ostream& Outfile) const;//Outputs the correct output

//private members of the class List.
private:

NodePtr head; I guess these are all pointers?
NodePtr tail;
NodePtr currptr;
NodePtr newNodeptr;
NodePtr searcher;
NodePtr trailer;

};

What exactly are the nodes?
0
Comment
Question by:awjackin35
8 Comments
 
LVL 3

Expert Comment

by:SEve
ID: 6211740
this link
http://swww.ee.uwa.edu.au/~plsd210/ds/lists.html
gives good picture about linked list, how it is built, what does it contain, what is "the node" and so on.
if you'll read it, i'm sure, you'll get answers to almost all of your questions.

good luck, seve

btw: link is a pointer to struct NodeType
0
 
LVL 4

Accepted Solution

by:
pluim earned 55 total points
ID: 6211761
Answers:
1. This is a forward declaration of NodeType. The actual declaration comes later. This is needed since the typedef statement uses NodeType. You need a structure because two data items need to be combined: the actual data (num2) and a pointer to the next element in the list (link).
Note that this is efficient but poor OO-programming. The structure NodeType should have been implemented as a class.

2. "NodePtr" is equivalent to "struct NodeType*". This aliasing could be done for a number of reasons. Most likely, the programmer thought "NodePtr" looked cleaner (or easier) than "struct NodeType*". It certainly is shorter.

3. Yes, link is a pointer. Its actual type is "struct NodeType*" (see 2). Or, in English, "Link is a pointer to a NodeType structure".

4. Yes, they are all pointers.

5. Each element in the list is a NodeType structure. These are the nodes. All the List class does is keep track of the last/ first/ current element, and offer some basic functions such as insert/ delete/ isEmpty. The actual data, as well as a pointer to the next element (node) is stored in a NodeType structure.
0
 
LVL 22

Expert Comment

by:nietod
ID: 6222863
Does anyone know if this accepted answer was posted as a comment or as an answer?
0
 
LVL 3

Expert Comment

by:SEve
ID: 6222871
i guess, pluim knows :-)
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 22

Expert Comment

by:nietod
ID: 6222894
If you haven't cleared your e-mail trash recently, you might be able to find the notification of pluim's post.  it will indicate if the post was a comment or answer.  (If you don't mind searching, that is.)
0
 
LVL 3

Expert Comment

by:SEve
ID: 6222940
i don't mind, but i don't keep this kind of messages for a long time. sorry

seve
0
 
LVL 22

Expert Comment

by:nietod
ID: 6228744
That's fine.

Anyone else know?  we're trying to measure the number of comments vs answers.
0
 

Author Comment

by:awjackin35
ID: 6229377
It was a comment
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now