RTL.SortVector Sample

From RAD Studio Code Examples
Jump to: navigation, search

This sample demonstrates how to sort a vector using the sort function of C++

Location

You can find the SortVector sample project at:

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

  1. Navigate to the location given above and open SortVector.cbproj.
  2. Select a target platform in the Projects Window.
  3. Press F9 or choose Run > Run.

Files

File Contains

SortVector.cbproj
SortVector.cpp

The project itself.

UIForm.h
UIForm.cpp
UIForm.fmx

The main form.

Unit2.h
Unit2.cpp

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

Samples