In: Computer Science
How do you translate this pseudocode to regular code in C++?
for i :1 to length(A) - 1
j = i
while j > 0 and A[j - 1] > A[j]
swap A[j] and A[j - 1]
j = j -1
Thee snippet is just for the sort the elements in the array in ascending order
#so code in c++
int length=sizeof(A)/sizeof(A[0]);
for(int i=1;i<length;i++){
int j=i;
while (j>0 && A[j-1]>A[j]){
int t=A[j];
A[j]=A[j-1];
A[j-1]=t;
j=j-1;
}
}

#sample source code along with output:

#if you have any doubt or more information needed comment below..i will respond as possible as soon..thanks..