Update: Using pointers instead of arrays and swap function added