Solved

Could someone answer my questions on this LL Header?

Posted on 2001-06-20
8
638 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 3

Expert Comment

by:SEve
ID: 6222871
i guess, pluim knows :-)
0
 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
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…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

860 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