#1 2022-06-03 13:31:06

rcv
Участник

Linked Sort 16

Input :

[V0] [V1] [V2] [V3] [V4] [V5] [V6] [V7]  [V8] [V9] [V10] [V11] [V12] [V13] [V14] [V15]
uint8_t Head = 0xFF
uint8_t Tail = 0xFF

[CNT0][NXT0] ... [CNT15][NXT15]

Output :

[sorted] , [length]

Code :

bool FindEntry( uint8_t *pret) {
 for(int i=0;i<16;i++) if(cnt[i]) { *pret = i; return true; }
 return false;
}
void LinkObjs() {

  uint8_t prevIdx = idxEntry;

  for(int i=idxEntry+1; i<16; i++) { if(cnt[i]) { nxt[prevIdx] = i; prevIdx = i; } }
  
  idxTail = prevIdx;

}

1. FindEntry(), if failed > nothing to sort
2. LinkObjs(), if idxTail  == idxHead > single component
3. SortCycle()


Testcases

1) All zero
2) Single component
3) Two components sort
4) Multiple components sort
5) Full spectrum components sort

Не в сети

Подвал раздела

Работает на FluxBB (перевод Laravel.ru)