RTL.SortVector Sample
This sample demonstrates how to sort a vector using the sort function of C++
Contents
Location
You can find the SortVector sample project at:
- Start | Programs | Embarcadero RAD Studio Athens | Samples and then navigate to:
CPP\RTL\SortVector
- Subversion Repository:
- You can find C++ code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version.
Description
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
SortVector.cbproj
. - Select a target platform in the Projects Window.
- Press
F9
or choose Run > Run.
Files
File | Contains |
---|---|
|
The project itself. |
|
The main form. |
|
The main functions used to generate and sort vectors. |
Classes
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.
Implementation
- 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
Uses
See Also
- Modern C++ Features Supported by RAD Studio Clang-enhanced C++ Compilers
- Standard Template Library (STL)
Samples
- Generic vector sort (C++)