Skip to content

Instantly share code, notes, and snippets.

@moshekaplan
Created September 13, 2012 02:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moshekaplan/3711559 to your computer and use it in GitHub Desktop.
Save moshekaplan/3711559 to your computer and use it in GitHub Desktop.
Simple example of creating a static 'Linked list' in C++
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;
}
@zeshanbhatti
Copy link

good, basic code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment