| | |
Why Data Structures???...QUESTIONS INSIDE
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jan 2005
Posts: 188
Reputation:
Solved Threads: 0
I HAVE SPECIFIC QUESTIONS!!!
1. Why do you need Self-Referential Classes? Please provide a "real" life example of when it would be used.
2. ^^^What is a Node, is it just a random name for this Class?
3. what does the (const Node *) mean in:
4. why is nextPtr the, "Link?"
I understand Dynamic Memory Allocation, somewhat, but
5. Can somebody break down these two lines of code form me?:
DEFINITION
A Linked List is a linear collection of self-referential class objects, called nodes, connected by pointer links.
6. What is that definition REALLY saying (plain english)?
According to my text book, "...if Nodes contain base-class pointers or base-class references to base-class and derived-class objects related by inheritance, we can have a linked list of such nodes and use Virtual Function calls to process these objects polymorphically...."
7. Can you please explain or provide an example of what is really being said here ^^^?
I think I understand how Stacks and Queues work, so I'll leave those alone until I think otherwise, but
8. How does a Tree work and what is it's purpose?
1. Why do you need Self-Referential Classes? Please provide a "real" life example of when it would be used.
C++ Syntax (Toggle Plain Text)
class Node { public: Node(int); void setData(int); int getData() const; void setNextPtr( const Node *); const Node *getNextPtr() const; private: int data; Node *nextPtr; };
2. ^^^What is a Node, is it just a random name for this Class?
3. what does the (const Node *) mean in:
C++ Syntax (Toggle Plain Text)
void setNextPtr(const Node *);
4. why is nextPtr the, "Link?"
I understand Dynamic Memory Allocation, somewhat, but
5. Can somebody break down these two lines of code form me?:
C++ Syntax (Toggle Plain Text)
Node *newPtr = new Node(10); delete newPtr;
DEFINITION
A Linked List is a linear collection of self-referential class objects, called nodes, connected by pointer links.
6. What is that definition REALLY saying (plain english)?
According to my text book, "...if Nodes contain base-class pointers or base-class references to base-class and derived-class objects related by inheritance, we can have a linked list of such nodes and use Virtual Function calls to process these objects polymorphically...."
7. Can you please explain or provide an example of what is really being said here ^^^?
I think I understand how Stacks and Queues work, so I'll leave those alone until I think otherwise, but
8. How does a Tree work and what is it's purpose?
•
•
Join Date: Apr 2005
Posts: 63
Reputation:
Solved Threads: 1
•
•
•
•
Originally Posted by Fasola
1. Why do you need Self-Referential Classes? Please provide a "real" life example of when it would be used.
•
•
•
•
Originally Posted by Fasola
2. ^^^What is a Node, is it just a random name for this Class?
•
•
•
•
Originally Posted by Fasola
3. what does the (const Node *) mean in:C++ Syntax (Toggle Plain Text)
void setNextPtr(const Node *);
•
•
•
•
Originally Posted by Fasola
4. why is nextPtr the, "Link?"
•
•
•
•
Originally Posted by Fasola
5. what does can somebody break down these two lines of code form me?:
C++ Syntax (Toggle Plain Text)
Node *newPtr = new Node(10); delete newPtr;
•
•
•
•
Originally Posted by fasola
DEFINITION
A Linked List is a linear collection of self-referential class objects, called nodes, connected by pointer links.
6. What is that definition REALLY saying (plain english)?
linear collection - collection in a linear(a line) order
I defined self-referential class objects above.
pointer links - this is where the Node * nextPtr comes into play, as I said above, points to the next node.
•
•
•
•
Originally Posted by Fasola
According to my text book, "...if Nodes contain base-class pointers or base-class references to base-class and derived-class objects related by inheritance, we can have a linked list of such nodes and use Virtual Function calls to process these objects polymorphically...."
7. Can you please explain or provide an example of what is really being said here ^^^?
•
•
•
•
Originally Posted by Fasola
8. How does a Tree work and what is it's purpose?
And if this post didn't help, here are some links regarding linked lists for you to do some further research:
http://www.inversereality.org/tutori...nkedlists.html
http://www.fredosaurus.com/notes-cpp/index.html go to structs near the bottom.
That should be enough to get ya started
>1. Why do you need Self-Referential Classes?
It's the easiest way to implement non-contiguous data structures. You don't need them, but they make life easier.
>2. ^^^What is a Node, is it just a random name for this Class?
Node
>3. what does the (const Node *) mean in
It's a pointer to a Node that shouldn't be modified.
>4. why is nextPtr the, "Link?"
That's basic data structure terminology. A "link" leads from one node to another.
>Node *newPtr = new Node(10);
It creates a Node, calls the constructor with the value 10, and assigns the address of it to newPtr.
>delete newPtr;
It releases the memory pointed to by newPtr. This only works predictably for memory returned by new.
>6. What is that definition REALLY saying (plain english)?
That's an awful explanation of a linked list. Sadly, it's not that simple when first introducing people to the concept. This provides more suitable information.
>7. Can you please explain or provide an example of what is really being said here ^^^?
Basically, you can have a linked list of polymorphic types.
>8. How does a Tree work and what is it's purpose?
Go here and read up on the tutorials that talk about binary trees. When someone talks about a tree, they usually mean a binary search tree.
It's the easiest way to implement non-contiguous data structures. You don't need them, but they make life easier.
>2. ^^^What is a Node, is it just a random name for this Class?
Node
>3. what does the (const Node *) mean in
It's a pointer to a Node that shouldn't be modified.
>4. why is nextPtr the, "Link?"
That's basic data structure terminology. A "link" leads from one node to another.
>Node *newPtr = new Node(10);
It creates a Node, calls the constructor with the value 10, and assigns the address of it to newPtr.
>delete newPtr;
It releases the memory pointed to by newPtr. This only works predictably for memory returned by new.
>6. What is that definition REALLY saying (plain english)?
That's an awful explanation of a linked list. Sadly, it's not that simple when first introducing people to the concept. This provides more suitable information.
>7. Can you please explain or provide an example of what is really being said here ^^^?
Basically, you can have a linked list of polymorphic types.
>8. How does a Tree work and what is it's purpose?
Go here and read up on the tutorials that talk about binary trees. When someone talks about a tree, they usually mean a binary search tree.
I'm here to prove you wrong.
•
•
Join Date: Jan 2005
Posts: 188
Reputation:
Solved Threads: 0
First of all Thank you both Marinme and Narue...that's real helpful
Na, That link you gave me to wikipedia was exactly what I needed. I've been going from one definition to another for the last hour and a half. I have a few interesting questions, but have run out of (session) time in this public library computer, will be back
Na, That link you gave me to wikipedia was exactly what I needed. I've been going from one definition to another for the last hour and a half. I have a few interesting questions, but have run out of (session) time in this public library computer, will be back
•
•
Join Date: Jan 2005
Posts: 188
Reputation:
Solved Threads: 0
Lets see if i've learnt anything and if I am getting this:
Okay so a Linked List is just a list of Nodes
Nodes are basicly just Structs/Classes
the Members of these Nodes contain data (such as Values of Objects) and Pointers to the previous or next Node on a Linked List
a Linked List's primary use is to access data (i.e. Nodes or Members of Nodes) that are not contiguously (i.e. adjacent) to eachother. So, it's safe to say a Linked List is primarily used to increase effiecency (i.e. speed up) the process of accessing data at runtime. It's kind of like an "Index" in general or in a database.
NOTE: I am not sure how to utilize this in real world programming!
damn, another session time has ended, I'll be back
Okay so a Linked List is just a list of Nodes
Nodes are basicly just Structs/Classes
the Members of these Nodes contain data (such as Values of Objects) and Pointers to the previous or next Node on a Linked List
a Linked List's primary use is to access data (i.e. Nodes or Members of Nodes) that are not contiguously (i.e. adjacent) to eachother. So, it's safe to say a Linked List is primarily used to increase effiecency (i.e. speed up) the process of accessing data at runtime. It's kind of like an "Index" in general or in a database.
NOTE: I am not sure how to utilize this in real world programming!
damn, another session time has ended, I'll be back
>can I get an example of a Binary Tree (top down)
The link I gave you covers these in detail.
>and a B-Tree (ground up)?
These are complicated enough that example code will be hard to find, but you shouldn't have any trouble finding B-tree info on google. I won't give you code or concepts because the search will be good for you.
>what the two types of Trees are good for, in real word programming?
Binary trees (usually of the binary search tree variation) have a wide range of uses. A good simple example is a large phonebook, where the records must be sorted, but still quickly accessible. B-trees are primarily used as external storage structures for databases.
The link I gave you covers these in detail.
>and a B-Tree (ground up)?
These are complicated enough that example code will be hard to find, but you shouldn't have any trouble finding B-tree info on google. I won't give you code or concepts because the search will be good for you.
>what the two types of Trees are good for, in real word programming?
Binary trees (usually of the binary search tree variation) have a wide range of uses. A good simple example is a large phonebook, where the records must be sorted, but still quickly accessible. B-trees are primarily used as external storage structures for databases.
I'm here to prove you wrong.
•
•
Join Date: Jan 2005
Posts: 188
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by Narue
>can I get an example of a Binary Tree (top down)
The link I gave you covers these in detail.
>and a B-Tree (ground up)?
These are complicated enough that example code will be hard to find, but you shouldn't have any trouble finding B-tree info on google. I won't give you code or concepts because the search will be good for you.
>what the two types of Trees are good for, in real word programming?
Binary trees (usually of the binary search tree variation) have a wide range of uses. A good simple example is a large phonebook, where the records must be sorted, but still quickly accessible. B-trees are primarily used as external storage structures for databases.
was i right about this (below):
http://www.daniweb.com/techtalkforum...22&postcount=5
>was i right about this (below):
More or less. Linked lists can be more efficient than arrays, but the inverse can also be true. It depends on what you need. You use an array when you need fast random access, you know roughly how many items ther will be, and items will only be added to the end of the array. This is because arrays can access any item with an index very quickly. With linked lists, you would be forced to follow links until you found the right item. However, insertion into an array is potentially expensive because you need to shift every item that goes after the new item to make room. Resizing an array (if possible) is tedious and error prone, so it's best avoided when possible.
You use a linked list when you don't know how many items there will be, you may insert an item anywhere in the list, and random access is not a primary goal. Because linked lists are non-contiguous, insertion is a trivial matter of simply resetting a few links, so the operation is very efficient no matter where you insert. Linked lists are inherently dynamic, so you don't have to bend over backward to get them to resize themselves.
>I am not sure how to utilize this in real world programming!
File processing. You need to read all of the lines in a file and then sort them. You could use an array, but then you would have to guess at how many lines are in the file, or try to implement a resizable array. Using a linked list is easier and cleaner. Now you have more comfortable options. For example, you can use an unsorted linked list, count the number of lines, then create an array of pointers and sort that, or you could maintain a sorted linked list from the start.
More or less. Linked lists can be more efficient than arrays, but the inverse can also be true. It depends on what you need. You use an array when you need fast random access, you know roughly how many items ther will be, and items will only be added to the end of the array. This is because arrays can access any item with an index very quickly. With linked lists, you would be forced to follow links until you found the right item. However, insertion into an array is potentially expensive because you need to shift every item that goes after the new item to make room. Resizing an array (if possible) is tedious and error prone, so it's best avoided when possible.
You use a linked list when you don't know how many items there will be, you may insert an item anywhere in the list, and random access is not a primary goal. Because linked lists are non-contiguous, insertion is a trivial matter of simply resetting a few links, so the operation is very efficient no matter where you insert. Linked lists are inherently dynamic, so you don't have to bend over backward to get them to resize themselves.
>I am not sure how to utilize this in real world programming!
File processing. You need to read all of the lines in a file and then sort them. You could use an array, but then you would have to guess at how many lines are in the file, or try to implement a resizable array. Using a linked list is easier and cleaner. Now you have more comfortable options. For example, you can use an unsorted linked list, count the number of lines, then create an array of pointers and sort that, or you could maintain a sorted linked list from the start.
I'm here to prove you wrong.
![]() |
Other Threads in the C++ Forum
- Previous Thread: NTVDM CPU has encountered an illegal instruction
- Next Thread: plz tell me wherez my mistake in dis program!!
| Thread Tools | Search this Thread |
api array based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news node numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






