// Soln4_4.cpp : main project file. #include "stdafx.h" using namespace System; // This uses an array of bool values to record which data values // have been output at any given time. A value that has been output // is marked as true in the used array, and only values that have a // corresponding true value in the used array are checked each time. int main(array ^args) { Random^ generator = gcnew Random; array^ values = gcnew array(generator->Next(10,20)); // Initialize the array of data value for (int i = 0 ; i < values->Length ; i++) values[i] = generator->Next(100,1000); // Create array to identify elements that have been output array^ used = gcnew array(values->Length); Array::Clear(used, 0, used->Length); // Set elements false Console::WriteLine(L"There are {0} values.", values->Length); int minimum = 0; // Current minimum int minIndex = 0; // Index of current minimum // Output the values in ascending sequence for(int count = 0 ; countLength ; count++) { // Find first candidate for minimum for(int i = 0 ; iLength ; i++) if(minimum == 0 && !used[i]) { minimum = values[i]; minIndex = i; break; } // Look for a lower minimum from remaining elements for(int i = minIndex+1 ; iLength ; i++) if(minimum>values[i] && !used[i]) { minimum = values[i]; minIndex = i; } used[minIndex] = true; // Record minimum as used Console::Write(L"{0,10}", minimum); // Write the minimum if((count+1)%5 == 0) // If it's multiple of 5 Console::WriteLine(); // Write a newline minimum = 0; // Reset minimum to 0 } Console::WriteLine(); return 0; }