Solved

Could someone answer my questions on this LL Header?

Posted on 2001-06-20
8
643 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying 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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

688 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