I wrote it quickly in Java, and the results of SWAP (i, J) were not exchanged (SWAP (R [i], R [J])
but swap (R, i, J) Yes, I do n’t understand, is n’t it all exchanges. Are it deterrent?????
3 thoughts on “SWAP function”
Leave a Comment
You must be logged in to post a comment.
Swap function, the role is to exchange the value of the two elements. Taking the source code of STL as an example:
template u003Cclass T> Void Swap (T
It is a simple type such as INT, which is the value of the value. After the value is changed, it will not affect the value of the call statement, and only valid in this function.
This array is not. It is the address. After the value is changed, the value of the call statement will also change.
The first swap (r [i], r [j]) is the value transfer, and the second is quoting transmission