/*******************************************************
* The "add2back(p,val)" function below works because of
* call-by-reference. After all, on the first call in
* main, we need L to be modified.
*******************************************************/
class Node
{
public:
int data;
Node* link;
Node(int x, Node* p) { data = x; link = p; }
};
// Note the silly use of short-circuit evaluation
// To avoid an "if". What was I thinking?
void add2back(Node* &p, int val)
{
p && add2back(p->link) || (p = new Node(val,NULL));
}
int main()
{
Node *L = NULL;
// Note the silly use of "for" just to put my whole
// loop on a single line. I must stop!
for(int x; cin >> x; add2back(L,x));
// Now do useful work with L!
}