Singly-linked list/Element definition: Difference between revisions

m
→‎[[C plus plus|C++]]: missing semicolon in C++ code and typo in text
(→‎[[C]]: Corrected C example (C needs the struct tag, or alternatively a typedef; also a semicolon was missing; added C++)
m (→‎[[C plus plus|C++]]: missing semicolon in C++ code and typo in text)
Line 37:
int data;
link(int a_data, link* a_next = 0): next(a_next), data(a_data) {}
};
 
With this constructor, new nodes can be initialized directly at allocation; e.g. the followingffollowing code creates a complete list with just one statement:
 
link* small_primes = new link(2, new link(3, new link(5, new link(7))));
973

edits