class List
	begin
		int value;  
		^List next;
	end

int freeNode = 0;
[ 20 ]List nodeHeap;

^List new( int value; ^List next; )
	begin
		^List node = nodeHeap[ freeNode++ ];
		node.value = value;
		node.next = next;
		return node;
	end

void printList( ^List a; ) 
	begin
		printf( "{ " );
		while a != null do
			printf( "%d", a.value );
			a = a.next;
			if a != null then
				printf( ", " );
			end
		end
		printf( " }\n" );
	end
	
void deleteAll( int value; ^List source; ^^List dest; )
	begin
		if source == null then
			dest^ = null;
		elif source.value == value then
			deleteAll( value, source.next, dest );
		else
			dest^ = new( source.value, null ); 
			deleteAll( value, source.next, &dest^.next );
		end
	end
	
^List source, a1, a2a, a4, a7, a2b, a9, dest;
a9 = new( 9, null );
a2b = new( 2, a9 );
a7 = new( 7, a2b );
a4 = new( 4, a7 );
a2a = new( 2, a4 );
a1 = new( 1, a2a );
source = a1;
deleteAll( 2, source, &dest );
printList( source );
printList( dest );
