Data Types and Structures

Complex data structures and their implementations.

Topics

Key terms

10.1 Data types and records

Data type
Defines what kind of value a variable can hold and what can be done with it.
Integer
A data type for whole numbers.
Real
A data type for numbers with a fractional part.
Char
A data type for a single character.
String
A data type for a sequence of characters.
Boolean
A data type with only two possible values, TRUE or FALSE.
Date
A data type for storing calendar dates.
User-defined data type
A data type created by the programmer to suit a particular need.
Enumerated type
A user-defined type with a fixed list of named values, such as the days of the week.
Pointer type
A type of variable that stores the memory address of another variable.
Composite data type
A data type built from other data types, such as a record or an array.
Record
A composite type grouping fields of different data types under one name. Fields are accessed with dot notation, for example Student.Name.

10.2 Arrays

Array
A collection of values of the same data type stored under one name.
Element
One value stored in an array.
Index
The number used to identify an element's position in an array.
Lower and upper bound
The first and last index of an array, for example ARRAY[1:10].
One-dimensional (1D) array
A list of values accessed with one index.
Two-dimensional (2D) array
A table of values accessed with two indices, such as row and column. ARRAY[1:4, 1:5] has 20 elements.

10.3 Text files

Text file
A file that stores data as lines of readable characters.
OPENFILE
Opens a file for READ, WRITE or APPEND.
READFILE
Reads a line of data from an open file.
WRITEFILE
Writes a line of data to an open file.
CLOSEFILE
Closes a file when the program has finished with it.
End of file (EOF)
A test that tells the program there is no more data to read from a file.

10.4 Abstract data types

Abstract data type (ADT)
A data structure defined by what it stores and the operations on it, not by how it is implemented.
Stack
A last in, first out (LIFO) structure where items are added and removed at the same end.
Push
Adds an item to the top of a stack.
Pop
Removes and returns the item at the top of a stack.
Stack pointer
Holds the position of the top item of a stack.
Queue
A first in, first out (FIFO) structure where items join at the rear and leave from the front.
Enqueue
Adds an item to the rear of a queue.
Dequeue
Removes and returns the item at the front of a queue.
Linked list
A collection of nodes, each holding data and a pointer to the next node.
Node
One item in a linked list, made of a data value and a pointer.
Null pointer
A pointer that points to nothing, used to mark the end of a linked list.
Stack overflow and underflow
Overflow is pushing onto a full stack. Underflow is popping from an empty one.

Practice questions for Data Types and Structures