Site hosted by Angelfire.com: Build your free website today!
« April 2006 »
S M T W T F S
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30
Entries by Topic
All topics  «
Blog Tools
Edit your Blog
Build a Blog
RSS Feed
View Profile
Open Community
Post to this Blog
You are not logged in. Log in
C++ Programs from Random Places
Sunday, 9 April 2006
Basic Structs
//THIS IS JUST AN INTRODUCTION TO STRUCTS
//**NOTE**: THIS CODE IS NOT COPYRIGHTED AND IS FREE FOR USE
//AND DISTRIBUTION

struct node {
int x;
node *next;
};

int main()
{
node *root; // This won't change, or we would lose the list in memory
node *conductor; // This will point to each node as it traverses the list

root = new node; // Sets it to actually point to something
root->next = 0; // Otherwise it would not work well
root->x = 12;
conductor = root; // The conductor points to the first node
if ( conductor != 0 ) {
while ( conductor->next != 0)
conductor = conductor->next;
}
conductor->next = new node; // Creates a node at the end of the list
conductor = conductor->next; // Points to that node
conductor->next = 0; // Prevents it from going any further
conductor->x = 42;

conductor = root;
while ( conductor != NULL ) {
cout<< conductor->x;
conductor = conductor->next;
}

}

Posted by poetry/maddoxtheconqueror at 12:01 AM CDT
Post Comment | Permalink | Share This Post

View Latest Entries