Professor Zhou Ligong's years of dedicated effort have resulted in two influential books: "Programming and Data Structure" and "Programming for AMetal Framework and Interface (I)". After their publication, a significant learning trend emerged within the electronics industry. With Professor Zhou’s authorization, this public account has serialized the content of "Programming and Data Structure", and is now sharing it with the community.
The second chapter focuses on programming techniques. This section specifically covers 2.2.5, which discusses structure arrays.
>>>
2.2.5 Structure Array
To illustrate the concept of multi-branch selection structures, we'll use the console menu as an example. Typically, a menu includes at least four functions: new file, open file, save file, and exit. Here's a sample layout:

If we use function pointers, these four functions can be called in the following way:

Each of these menu options—new file, open file, save file, and exit—can be stored as strings in char arrays, such as "new file", "open file", "save file", and "exit".

Based on this, we can define a structure type called `CmdEntry`, which contains a function pointer and a help string. The declaration would look like this:

Next, we can create a structure array that acts as a function table, storing the entry addresses and menu information for each function. The declaration might look like this:

Here, `cmdArray` is an array of 10 elements, where each element is a `CmdEntry` structure. So, `cmdArray[0]` is the first structure variable, `cmdArray[1]` is the second, and so on.
To access members of the structure array, we use the dot operator after the structure name. For example:

Note that the array index comes immediately after the structure array name, not after the member name. For instance:

The reason we use `cmdArray[2].cHelp` is because `cmdArray[2]` is the name of the structure variable. Similarly, `cmdArray[3].cHelp` refers to another structure variable in the array.
Since the array name represents the address of the first element, the following two statements are equivalent:

Then, `*pCmdEntry = cmdArray[0]`. Because `&` and `*` are inverse operators, we can also write:

Due to operator precedence, parentheses are necessary. By the way, what does the following expression mean?

This refers to the second character (`cHelp[1]`) of the first structure variable (`cmdArray[0]`) in the `cmdArray` array. That character is "b". This example shows how subscripts work both on the array of structures and on individual members.
In summary:

Using this definition, you can retrieve the function address as follows:

This means the `pfuncmd` function pointer points to the `CreateFile()` function, which can then be called like this:

As shown, using dynamic binding through callback functions greatly enhances program scalability. Simply adding a custom function at the marked location allows for easy expansion without changing existing code, reducing errors and improving maintainability. For more details, refer to Listing 2.26.
**Listing 2.26 Console Menu Options**

Now, complete this exercise by implementing the `bubbleSort()` algorithm. Sort the `employeeArray` structure array according to the following criteria and output the results:
1. Sort by `id` from smallest to largest.
2. Sort by `weight`, `age`, and `height` from smallest to largest. If these values are equal, sort by `id`.
3. Sort by `bloodType` in the order A, B, O, AB. If they are the same, sort by `id` from smallest to largest.
Rental LED Transparent Screen,Translucent LED panel,Transparent LED display,See-through LED display,Transparent LED Video Wall,High transparency LED screen
Shenzhen Xinfei Century Technology Co., Ltd. , https://www.rgbdancing.com