What are alternatives to this method
tmp = c[0];
c[0] = c[1];
c[1] = c[2];
c[2] = c[3];
c[3] = tmp;
to left rotate a char array with 4 elements
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Using generics and rotating in place (thanks Jon Skeet for the suggestion):
These should work for any array of at least 2 length, and on any array.
If performance is critical and the arrays are always small, use this:
The first method is the fastest with large arrays, but for 4 items, this one’s almost as fast as your example method.