I take an introductory course in C ++ where we learn to implement mergesort. I try to go through every step in the code, but there is one part that disables me:
1. void mergeSort(int *x, int len){
2. if (len>1){
3. int newLen=len/2;
4. mergeSort(x, newLen);
5. mergeSort(x+newLen,len-newLen);
6. int *newSeq;
7. newSeq=new int[len];
8. mTwoSeq(x, x+newLen, newSeq,newLen, len-newLen);
9. for(int i=0;i<len;++i){
10. x[i]=newSeq[i];
11. }
12. delete[] newSeq;
13. }
14. }
What happens on line 5? As far as I understand, when we call "x + i", where x is an array of pointers, we ask the computer to give us the address of the part of the memory that stores the ith part of the data. If so, I'm not quite sure how that fits here. If someone knows what happens in the call to this function, I would be very happy to know. Thank!
source
share