add swap function and set initial value for createMatrix function.