hi, just wanna see some saple codes implenting OOP(classes) using linked list...thank you
C++ linked list?
Quick and dirty with structs (wouldn't be much of an issue to turn this into a class):
struct node
{
MyData data;
struct node* next;
};
MyData is whatever you want to keep a list of (ints, floats, garbage cans).
To build a list like this:
struct node* head = new struct node;
head-%26gt;data = [whatever];
head-%26gt;next = NULL;
// list has one element
// add another
struct node* elem = new struct node;
elem-%26gt;data = [whatever];
elem-%26gt;next = NULL;
head-%26gt;next = elem;
// Iterate through the list:
struct node* curr = head;
while(curr != NULL)
{
// do something with curr
curr = curr-%26gt;next;
}
Reply:Try this website:
http://www.inversereality.org/tutorials/...
for a tutorial.
Hope this helps!
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment