two-exchange begins

wrote generic functions independent of data structure used.