Created
September 13, 2012 02:58
-
-
Save moshekaplan/3711559 to your computer and use it in GitHub Desktop.
Simple example of creating a static 'Linked list' in C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct node{ | |
// A node has two components: some data and a pointer to the next node. | |
int node_data; | |
node* next; | |
}; | |
int main(){ | |
// Make some nodes: | |
node A,B,C; | |
// Make a reference to the 'front' of the list | |
node* start; | |
// Make the list start at 'A' | |
start = &A; | |
// Create a link from 'A' to 'B' | |
A.next = &B; | |
// Create a link from 'B' to 'C' | |
B.next = &C; | |
// Give 'C' a special value to show it's the end of the list: | |
C.next = NULL | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
good, basic code