CHAPTER 10: DATA TYPES AND STRUCTURES 10.1 DATA TYPES 10.1.1 Primitive Data Types Type Description INTEGER Whole numbers REAL Decimal numbers CHAR Single character STRING Sequence of characters BOOLEAN True/False DATE Date values 10.1.2 Records Definition: A structure that holds a set of data of different types under one identifier. Purpose: Group related data of different types Like a record in a database Example: RECORD Employee DECLARE EmpID : INTEGER DECLARE Name : STRING DECLARE Salary : REAL END RECORD 10.2 ARRAYS 10.2.1 One-Dimensional Arrays Definition: A collection of elements of the same type accessed by index. Terms: Index: Position of element Lower bound: First index (usually 0 or 1) Upper bound: Last index Declaration: DECLARE arrayname[upperbound] : TYPE Access: arrayname[index] 10.2.2 Two-Dimensional Arrays Definition: Array of arrays; elements accessed by row and column. Declaration: DECLARE arrayname[row, column] : TYPE 10.2.3 Array Operations Linear Search: Check each element sequentially Works on unsorted data O(n) time complexity Bubble Sort: Compare adjacent elements Swap if in wrong order Repeat until sorted O(n²) time complexity 10.3 FILES 10.3.1 File Need Store data permanently Large amounts of data Data persistence between program runs 10.3.2 File Operations Opening: OPENFILE filename FOR READ/WRITE/APPEND Reading: READFILE filename, variable Writing: WRITEFILE filename, variable Closing: CLOSEFILE filename 10.4 ABSTRACT DATA TYPES (ADT) 10.4.1 Stack Characteristics: LIFO (Last In, First Out) Add to top (push) Remove from top (pop) Operations: Push: Add item to top Pop: Remove item from top Peek: View top item without removing 10.4.2 Queue Characteristics: FIFO (First In, First Out) Add to rear (enqueue) Remove from front (dequeue) 10.4.3 Linked List Characteristics: Dynamic structure Nodes contain data and pointer to next node Can grow/shrink easily Operations: Add node Delete node Search