Solved

Could someone answer my questions on this LL Header?

Posted on 2001-06-20
8
628 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

759 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

17 Experts available now in Live!

Get 1:1 Help Now