Ch. 10 Data types and structures
10.1 Data types and records
INTEGER, REAL, CHAR, STRING, BOOLEAN, DATE, ARRAY, FILE
Record structure
- A set of related data items
- Can be different data types
Read data from a record structure
Save data to a record structure
10.2 Arrays
- A data structure in a program that uses the same identifier name for several data values
- Used for a collection of items of the same data type
10.3 Files
OPENFILE "File1.txt" FOR WRITE
WRITEFILE "File1.txt", EmployeeString
CLOSEFILE "File1.txt"Write mode is for new files
Append mode is to add a line of text to the end of the existing file
10.4 Introduction to Abstract Data Types (ADT)
ADT is a collection of data and a set of operations on those data
Understanding that a stack, queue and linked list are examples of ADT
Stack
- Last item added will be the first to leave
Queue
- First item added will be the first to leave
Linked list
- A data structure consisting of a set of nodes
- Each node consists of the data value and a link pointer to one of the other nodes
- The purpose is to link the nodes in some particular order
Use them to store data
Describe how a queue, stack and linked list can be implemented using arrays
Stack
- Store the values in an array: lower bound 1 and upper bound N
- A pointer indicates the position of the item that is currently at the top of the stack
Queue
- Store the values in an array: lower bound 1 and upper bound N
- The queue is controlled by two pointers, a head pointer which points to the item that is currently at the head of the queue, a tail pointer points to the item that is currently at the rear of the queue
- A new item is always added to the end of the queue
Linked list
- Store the data using two 1D arrays
- First array for the data values
- Second array for the link pointers
- A start pointer is needed, which is the array index of the first item in the list
- A next free position index pointer is needed to show where the next new value is stored
