Problem: Reverse an integer array bitwise algorithm

Example:
i/p : A[]{1,2,3,4,5}

o/p: A[]{5,4,3,2,1}

Process:
//1. Declare Assumptions
//2. Explain algo
//3. take an Example
//4. give testcases
//5. 1st write the solution
//6. then add exception handels and try/catch/finally blocks
//7. Order

ALGO:
//check for even or odd
//using a swap method swap using XOR swap

TEST CASES:

//Functional:
//1. empty array
//2. odd/even array
//3. negative numbers
//4. large numbers[32767]
//5. characters

Non-Functional:

Performance
//1. same array used multiple time test for time complexity
//Memory
//2. same array tested for multiple time test for memory leakage
//Security
//3. test with array having escape characters
//4. test with array have special char or ASCII values
//Stress
//6. run multiple instance of the method and test for stress

Load
//7. test with very large array
//Globalisation/localisation
//8. test with unicode char
//9. test with kanji char
//10. test with mix of both characters

CodeCoverage
Exception Handelling
//11. test whether exceptions are handelled.

TEST HARNESS:

using System;
namespace problem
{
public class answer
{
static void Main()
{
int[] A=new int[5]{1,2,3,4,5};
bitreverse(A);
Console.ReadLine();
}
CODE:
public static void bitreverse(int[] A)
{

try
{
int j=A.Length-1;

for (int i=0; j>i; i++, j--)
{
A[i]=A[i]^A[j];
A[j]=A[i]^A[j];
A[i]=A[j]^A[i];
}
}
catch(Exception ex)
{
Console.WriteLine(ex);
}

}
ORDER: O(N)
Subscribe - To get an automatic feed of all future posts subscribe here, or to receive them via email go here and enter your email address in the box. You can also like us on facebook and follow me on Twitter @akashag1001.