In this chapter we will define a set of general purpose functions that can be stored in a library and used from any application.
The set of functions that we define will form a new type of data for the handling of the tracks, and if an application wants to use them, it can do so through this new type of data as if it were functions of the standard library C. Let's start by defining the tracks and their functions.
A list will be defined by two demonstrators, one to indicate the first component and the other for the last. Each of the components in the list has a pointer to indicate the component next to the saliva, the component information index and priority, as it is possible to enter the components in priority order. Program 1 shows the contents of the lista_def.h file, where the list is made and the component is defined.
The list functions that the applications will need will then be designed and defined.
From the design point of view, you must specify what type of functions they will be and what parameters they will have. To begin with, we will need the function of creating an empty list, which has as only parameter the created, the breeze index. To know if it is a simple list, we will have a boolean function with a single parameter, the empty function. As the lists add the components and delete them, the main functions will be to add them at the end (regardless of priority) or add them in order of preference, and delete the first component or remove the first component from a given priority. Associating, inserting, first and leaving these four functions will correspond to the following names and characteristics:
The designed functions will be reflected in the lista_fun.h file, since in the applications this file will be used to create functions on lists.
The following programs have started the definition of functions 3 to 8, all of them being included in a file or in separate files. At the beginning of each file, the #include lista_def.h.
Figure 1 reflects the normal state, i.e. the element inserted is not the first or the last.
The inverse functions of tying and inserting are the first and exit, as instead of tying an element remove it.
Once these functions are compiled, it is convenient to store them in a library to facilitate the linking procedure when referencing from applications. The functions of the previous chapter were not located in a library because they were written for a specific application, but the purpose of the functions of this chapter is to offer a new type of data for any application, so the standard procedure is to be located in a library.
Each object module storage operating system in libraries has a command, as discussed in chapter 11.
If the library is complete, let's see how the mentioned functions saved in the library can be used.
We will explain it by example. Let's think that in the database of the previous chapter we want to list the books by date of publication. As indicated in Program 9, we will define a list and its components will be placed in the dynamic memory.
Each of the components or elements of the List is composed of the enclosed demonstrator, the date of publication as a priority and the index for the corresponding book. Once the list is completed by running all the books, the components will be removed and printed in order.
Note that the list and elements, which so far had no memory assigned, have been defined in the main program, one in static memory and one in dynamic memory. On the other hand, the functions associated with the lists are not managed, since the lista_fun.h file is included.
Linking the program will refer to the library to which the lists belong.
Saioa hasi iruzkinak uzteko.