Thursday, July 9, 2009

C++ array help?

how do you reverse the array integers like for example





3 5 6 7 8(first array) to 8 7 6 5 3(reversed array)





by the use of a definition funtion, how should i reverse the first array so it will be reversed.

C++ array help?
pass the original array into a function. then use a for loop starting wih the end of the array to fill up ur new array that will be reversed.u can find the length of the original array, and then start like this.





int size = originalarry.length;





for (int j=0,i = size-1;i%26lt;=0;i--,j++)


{


newarray[j]=originalarray[i];


}





put that into ur function, and return the newaray. try it.
Reply:int buffer;


int *p1 = array;


int *p2 = array + (array_len -1);


while (p1 %26lt; p2)


{


buffer = *p1;


*(p1++) = *p2;


*(p2--) = buffer;


}

local florist

No comments:

Post a Comment