This sample demonstrates how to sort a vector using the sort function of C++
You can find the SortVector sample project at:
- Start | Programs | Embarcadero RAD Studio Rio | Samples and then navigate to:
- Subversion Repository:
The SortVector sample demostrates how to sort a random vector of integers. First, the sample generates the random vector and then, sorts it into ascending order. It uses two TListBox objects to display both the random and the sorted vector. Each item of each TListBox object is used to display each number.
How to Use the Sample
- Navigate to the location given above and open
- Select a target platform in the Project Manager.
F9or choose Run > Run.
The project itself.
The main form.
The main functions used to generate and sort vectors.
TForm3 is the main form that represents the main window of the sample. It contains the following components:
- Two TListBox objects labeled as ListBox1 and ListBox2.
- Two TButton objects labeled as Button1 and Button2.
- The sample uses TListBox to
- The sample uses TButton to enable or activate a function such as generating random numebrs.
When you run the application, the sample shows two buttons: Generate Numbers and Sort. When you click on GenerateNumbers, the sample generates a list of 10000 integer random numbers. While generating the vector of random numbers, each number is added to an item of ListBox1. Therefore ListBox1 shows the all the random numbers. Once the vector of random numbers has been created, you can click on the Sort button in order to sort the vector into ascending order. To this end, the sample uses the sort function of C++. The ordered vector is shown in ListBox2
- Generic vector sort (C++)