Two things I would point out:
First, in your original code, the source of the seg fault is that you are using Hi as a basis for your memory allocation, but Hi is a 0-based index.
Second, to do this without allocating memory, you can perform the swap in place. First, think of how you would...