void TestArraySorting2(void) { CArrayInt cInts; cInts.Init(); cInts.Add(4); cInts.Add(3); cInts.Add(2); cInts.Add(1); cInts.QuickSort(); AssertInt(1, cInts.GetValue(0)); AssertInt(2, cInts.GetValue(1)); AssertInt(3, cInts.GetValue(2)); AssertInt(4, cInts.GetValue(3)); cInts.Kill(); cInts.Init(); cInts.Add(4); cInts.Add(3); cInts.Add(2); cInts.Add(1); cInts.BubbleSort(); AssertInt(1, cInts.GetValue(0)); AssertInt(2, cInts.GetValue(1)); AssertInt(3, cInts.GetValue(2)); AssertInt(4, cInts.GetValue(3)); cInts.Kill(); }
int CInputDeviceDesc::GetUnusedID(void) { int i; CInputDevice* pcDevice; CArrayInt aiIDs; int iID; if (mapcDevices.NumElements() == 0) { return 0; } else if (mapcDevices.NumElements() == 1) { pcDevice = *mapcDevices.Get(0); if (pcDevice->GetDescriptionID() == 0) { return 1; } return 0; } aiIDs.Init(); for (i = 0; i < mapcDevices.NumElements(); i++) { pcDevice = *mapcDevices.Get(i); aiIDs.Add(pcDevice->GetDescriptionID()); } aiIDs.QuickSort(); iID = aiIDs.FindUnusedInSorted(); aiIDs.Kill(); return iID; }
void TestArrayIntSorting(void) { CArrayInt cArray; cArray.Init(1); cArray.AddList(-1, 4, 3, 7, 8, 1, 9, 0, 2, 4, 2, -1); cArray.QuickSort(); AssertInt(10, cArray.NumElements()); AssertInt(0, cArray[0]); AssertInt(1, cArray[1]); AssertInt(2, cArray[2]); AssertInt(2, cArray[3]); AssertInt(3, cArray[4]); AssertInt(4, cArray[5]); AssertInt(4, cArray[6]); AssertInt(7, cArray[7]); AssertInt(8, cArray[8]); AssertInt(9, cArray[9]); cArray.InsertIntoSorted(7, FALSE); cArray.InsertIntoSorted(1, TRUE); AssertInt(11, cArray.NumElements()); AssertInt(0, cArray[0]); AssertInt(1, cArray[1]); AssertInt(2, cArray[2]); AssertInt(2, cArray[3]); AssertInt(3, cArray[4]); AssertInt(4, cArray[5]); AssertInt(4, cArray[6]); AssertInt(7, cArray[7]); AssertInt(7, cArray[8]); AssertInt(8, cArray[9]); AssertInt(9, cArray[10]); cArray.Kill(); }