viewing paste Reverse | C#

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
/*******************************************************************************
    ArrayReversefunc.cpp
     
    This function is used to reverse an integer array.  For example, if the
    array is {1,2,3,4,5}, these functions will return an array like {5,4,3,2,1}.
    The user needs to pass in a pointer to the array and the size of the array,
    and the function will return a pointer to an array in the reverse order.
     
    John Shao
********************************************************************************
    This work is hereby released into the Public Domain. To view a copy of the
    public domain dedication, visit
    http://creativecommons.org/licenses/publicdomain/
 
    or send a letter to
 
    Creative Commons
    559 Nathan Abbott Way
    Stanford, California 94305
    USA.
*******************************************************************************/
 
int*ReverseArray(int*orig,unsigned short int b)
{
    unsigned short int a=0;
    int swap;
     
    for(a;a<--b;a++) //increment a and decrement b until they meet eachother
    {
        swap=orig[a];       //put what's in a into swap space
        orig[a]=orig[b];    //put what's in b into a
        orig[b]=swap;       //put what's in the swap (a) into b
    }
     
    return orig;    //return the new (reversed) string (a pointer to it)
}
 
/******************************************************************************/
/*                  The Following is a test program                           */
/******************************************************************************/
/* 
/* Note that this test program requires C++ but the function does not */
#include<iostream>
 
int main()
{
    const unsigned short int SIZE=10;
    int ARRAY[SIZE]={1,2,3,4,5,6,7,8,9,10};
    int*arr=ARRAY;
     
    for(int i=0;i<SIZE;i++)
    {
        std::cout<<arr[i]<<' ';
    }
    std::cout<<std::endl;
    arr=ReverseArray(arr,SIZE);
    for(int i=0;i<SIZE;i++)
    {
        std::cout<<arr[i]<<' ';
    }
    std::cout<<std::endl;
    std::cin.get();
    return 0;
}
*/
Viewed 980 times, submitted by Guest.