include <iostream>
struct btnode { int data; btnode* next ; } ;
btnode* push_back( btnode* first, int value )
{
if( first == nullptr ) returnnew btnode { value, nullptr } ;
btnode* n = first ;
for( ; n->next != nullptr ; n = n->next ) ; // traverse to the last node (the one just before the nullptr)
n->next = new btnode { value, nullptr } ; // add a new node at the end
return first ;
}
int main()
{
// note: delete, exception-safety etc. elided for brevity
btnode* first = nullptr ;
for( int i = 0 ; i < 16 ; ++i ) first = push_back( first, i*i ) ;
for( auto n = first ; n != nullptr ; n = n->next ) std::cout << n->data << ' ' ;
std::cout << '\n' ;
}
btptr T=S; // pointer variable T points to same place as S
T=S->ptr; // now T points to the same place as S->ptr
T=newstruct btnode; // now T points to a new btnode