c++11 - C++ void reverse function -
we converting base 10 number in different base(b). having trouble void reverse function not reverse order of numbers.
string converttobaseb(int num, int b){ int digit; stringstream answer; string x=""; while(num>0){ digit=num%b; num/=b; answer<<digit; } return answer.str();} void reverse(int x[],int size){//reversing for(int k=0; k<size/2; k++){ int temp=x[k]; x[k]=x[size-k-1]; x[size-k-1]=temp;} }
your reverse function works fine. doesn't looks c++ me... in c++ have vector , do:
std::vector<int> arr; //... fill arr std::swap_ranges(&arr[0], &arr[arr.size()/2], arr.rbegin());
if want stick loop, @ least use std::swap this
void reverse(int x[],int size) { for(int k=0; k<size/2; k++) std::swap(x[k], x[size-k-1]); }