1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | uint32 PointAt = 1;
int32 GetValueNext = SampleData[PointAt];
for(uint32 SampleIndex = 1;
SampleIndex < Result.SampleCount - 1;
++SampleIndex)
{
int32 GetValue = GetValueNext;
uint32 WasPoint = PointAt;
PointAt = RoundUpStub(PointAt/2); // Round up, also a stub
if(IsOddThisReallyIsAStub(WasPoint)) // Check if value is an odd number
{
PointAt = PointAt+Result.SampleCount/2-1;
GetValueNext = SampleData[PointAt];
SampleData[PointAt] = GetValue;
}
else
{
GetValueNext = SampleData[PointAt];
SampleData[PointAt] = GetValue;
}
}
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | #include <stdint.h> #include <stdio.h> int main() { int16_t SampleData[] = { 1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7, 8, -8 }; uint32_t SampleCount = 8; uint32_t PointAt = 1; int16_t GetValueNext = SampleData[PointAt]; for (uint32_t SampleIndex = 1; SampleIndex < SampleCount - 1; ++SampleIndex) { int16_t GetValue = GetValueNext; uint32_t WasPoint = PointAt; PointAt = (PointAt+1)/2; if (WasPoint & 1) { PointAt = PointAt + SampleCount/2 - 1; GetValueNext = SampleData[PointAt]; SampleData[PointAt] = GetValue; } else { GetValueNext = SampleData[PointAt]; SampleData[PointAt] = GetValue; } } for (uint32_t i=0; i<SampleCount*2; i++) { printf("%i ", SampleData[i]); } printf("\n"); } |
1 | 1 3 -1 -2 -1 -3 4 -4 5 -5 6 -6 7 -7 8 -8 |
1 | 1 2 3 4 5 6 7 8 -1 -2 -3 -4 -5 -6 -7 -8 |
1 | 1 5 -1 -2 2 -3 4 -4 3 -5 6 -6 7 -7 8 -8 |
m1el
So you're probably trying to implement this:
en.wikipedia.org/wiki/In-place_matrix_tr...Following_the_cycles
But your program will fail because there might be several cycles to follow. And finding such cycles is kind of a hard problem with no additional space. I wrote this kind of algorithm myself:
forums.handmadehero.org/index.php/forum?...topic&catid=4&id=710