samedi 23 octobre 2021

My functions to rotate the contents of memory to right/left not working correctly

void MoveRight()
{
    for (int i = 0; i < numbersCount; ++i)
    {
        pNumbers[i + 1] = pNumbers[i];
    }
    pNumbers[0] = pNumbers[numbersCount];
}

void MoveLeft()
{
    for (int i = numbersCount; i > 0; --i)
    {
        pNumbers[i - 1] = pNumbers[i];
    }
    pNumbers[numbersCount] = pNumbers[0];
}

In the class,

pNumbers = new int[sizeof(int) * numIntegers];

Let's say numbersCount value I have set to is 5.

So I used some test data and it seems instead of moving data right/left, it's just copying the first and last data?

What am I doing wrong?

Aucun commentaire:

Enregistrer un commentaire