Page 314 - Introduction to Microcontrollers Architecture, Programming, and Interfacing of The Motorola 68HC12
P. 314

io






               Elementary Data Structures












         In all the earlier chapters, we have used data structures along with our examples. While
         you should therefore be somewhat familiar with them, they need to be systematically
         studied. There are endless alternatives to the ways that data are stored, and so there is a
         potential for disorder. Before you get into a crisis due to the general disarray of your data
         and then convince yourself of the need for data structures, we want you to have the tools
         needed to handle that crisis. In this chapter, we systematically cover the data structures
         that are most useful in microcomputer systems.
            The first section discusses what a data structure is in more detail. Indexable
         structures, including the frequently used vector, are discussed in the second section. The
         third section discusses sequential structures, which include the string and the stack
         structures. The linked list is briefly discussed next, only to give you an idea of what it
         is, while the conclusions summarize the chapter with recommendations for further
         reading on data structures.
            At the end of this chapter, you should be able to use simple data structures, such as
         vectors and strings, with ease. You should be able to handle deques and their derivatives,
         stacks and queues, and you should know a linked list structure when you see one. This
         chapter should provide you with the tools that you need to handle most of the problems
         that cause confusion when storing data in your microcomputer programs.



         10.1 What a Data Structure Is

         In previous chapters, we described a data structure as the way data are stored in memory.
         While this description was adequate for those earlier discussions, we now want to be
         more precise. A data structure is more or less the way data are stored and accessed. This
         section expands on this definition.
            A data structure is an abstract idea that is used as a reference for storing data. It is
         like a template for a drawing. For example, a vector is a data structure that we have used
         since Chapter 3. Several sets of data can be stored in a vector in the same program and
         the same "template" is used to store each set. You may write or see a program that uses
         vectors that have five 1-byte elements. While writing another program, you may
         recognize the need for a vector that has five 1-byte elements and, by using the same


                                           291
   309   310   311   312   313   314   315   316   317   318   319