Section 10 - Data Types and Structures - 10.1.1 To 10.4.3 1
Section 10 - Data Types and Structures - 10.1.1 To 10.4.3 1
Boolean Logical values, True (1) and False (2) BOOLEAN bool
10.1.2 - Records
Composite Data Type: a data type constructed using several of the basic data types available in
a programming language
Record: it is a composite data type formed by the inclusion of several related item of different
data types
Format Example
TYPE TYPE
<Typename> TbookRecord
DECLARE <identifier> : <data type> DECLARE title : STRING
DECLARE <identifier> : <data type> DECLARE author : STRING
DECLARE <identifier> : <data type> DECLARE publisher : STRING
ENDTYPE DECLARE noPages : INTEGER
DECLARE fiction : BOOLEAN
ENDTYPE
10.2.1 - 1D Arrays
Array: it is a data structure containing several elements of the same data type. The elements
can be accessed using the same identifier name
What is a 1D Array?
It can be referred to as a list
10.2.2 - 2D Arrays
What is a 2D Array?
It can be referred to as a table, with rows and columns
Linear Search: it is a method for finding items stored in an array. Each element of the array is
checked from lower to upper bound until the item is found.
Algorithm Explained:
Computer programs store data in a file. Every file is identified by its filename
Pseudocode for opening a file: OPEN <file identifier> FOR <file mode>
The first item added to a stack is The first item added to a queue is A new item is always added to
the last item removed the first item removed the start of the list
Note:
- Items can be added to the stack (push) and removed (pop)
- Items can be added to the queue (enqueue) and removed (dequeue)
Use of Pointers:
Stacks, queues and linked lists make use of pointers to manage their operations. Items in
stacks and queues are added at the end. Linked lists use an ordering algorithm to order them in
ascending or descending order.
Front Pointer: points to the first item in the stack Front Pointer: points to the first item in the queue
Top Pointer: points to the last item in the stack Rear Pointer: points to the last item in the queue
The pointers are equal when there’s only one item The pointers are equal where there’s only one
in the stack item in the queue
The value of the base pointer remains the same during stack operations. A stack can be
implemented using an array and a set of pointers
Items can be removed from any position in the linked list, the empty positions in the array must
be managed as a empty linked list, called the heap
For Example
The startPointer = –1, as the list has no elements. The heap is set up as a linked list ready for
use.
The startPointer is set to the element pointed to by the heapPointer where 37 is inserted. The
heapPointer is set to point to the next element in the heap by using the value stored in the
element with the same index in the pointer list. Since this is also the last element in the list the
node pointer for it is reset to –1.
The startPointer is changed to the heapPointer and 45 is stored in the element indexed by the
heapPointer. The node pointer for this element is set to the old startPointer. The node pointer for
the heapPointer is reset to point to the next element in the heap by using the value stored in the
element with the same index in the pointer list.