Paper 2 · Unit 10. Data types, records, arrays, text files and abstract data types.

1. Data types and records

TypeUse
INTEGERWhole numbers
REALNumbers with a fractional part
CHARA single character
STRINGA sequence of characters
BOOLEANTRUE or FALSE
DATEA calendar date

A record is a user-defined composite type that groups related items of different types:

TYPE StudentRecord
   DECLARE Name : STRING
   DECLARE Age : INTEGER
   DECLARE Passed : BOOLEAN
ENDTYPE
DECLARE Pupil : StudentRecord
Pupil.Name ← "Aylin"

2. Arrays

An array is a fixed-size, indexed collection of elements of the same type. You need: index, lower and upper bound, 1D and 2D arrays.

DECLARE Scores : ARRAY[1:30] OF INTEGER
DECLARE Grid : ARRAY[1:3, 1:4] OF CHAR

// linear search
Found ← FALSE
Index ← 1
WHILE Found = FALSE AND Index <= 30
   IF Scores[Index] = Target THEN Found ← TRUE ENDIF
   Index ← Index + 1
ENDWHILE

// bubble sort
FOR Pass ← 1 TO 29
   FOR J ← 1 TO 30 - Pass
      IF Scores[J] > Scores[J + 1] THEN
         Temp ← Scores[J]
         Scores[J] ← Scores[J + 1]
         Scores[J + 1] ← Temp
      ENDIF
   NEXT J
NEXT Pass

3. Files

Files store data permanently so it is kept after the program ends. Text files are opened in a mode:

OPENFILE "scores.txt" FOR WRITE   // also READ, APPEND
WRITEFILE "scores.txt", Line
CLOSEFILE "scores.txt"

OPENFILE "scores.txt" FOR READ
WHILE NOT EOF("scores.txt")
   READFILE "scores.txt", Line
   OUTPUT Line
ENDWHILE
CLOSEFILE "scores.txt"

4. Abstract data types

ADTDescriptionPointers
StackLast In First Out (LIFO); items are pushed and popped at the topTop of stack (base pointer fixed)
QueueFirst In First Out (FIFO); enqueue at the rear, dequeue at the front; often circularFront and rear pointers
Linked listEach node holds data and a pointer to the next node; order is kept without moving dataStart pointer; null pointer ends the list; free list for unused nodes

All three can be implemented using arrays and pointer variables. Check for overflow (full) and underflow (empty).

Try it: stack vs queue

5. Examiner tips

  1. Arrays hold one data type; records hold different types.
  2. Always check bounds and use the bounds given in the question.
  3. Close files after use, and use EOF when reading.
  4. Stack = LIFO, queue = FIFO. Say which pointer changes.
  5. Linked list insertion changes pointers, not data positions.

6. Practice questions

Practice: answer and check instantly

Type a short answer, then press Check or Enter.

Show answer

BOOLEAN.

Show answer

REAL.

Show answer

First In First Out.

Show answer

Underflow.

Show answer

APPEND.

Show answer

EOF.

Show answer

A null pointer.

Show answer

3 × 4 = 12.

Exam-style questions

9. Describe how an item is added to a queue implemented with an array. [3]

Show mark guide

Check whether the queue is full (overflow) [1] · increment the rear pointer, wrapping round if circular [1] · store the item at the position of the rear pointer [1].

10. Explain why a record data type is useful. [2]

Show mark guide

It groups related data items of different data types [1] under one identifier, so data for one entity (e.g. a student) is kept together and easier to process [1].

7. Topic test: predict your grade

Topic test: predict your grade

15 questions, about 10 minutes. Answer them all, then press Mark my test.

1. A REAL stores…
2. A record…
3. An array element is accessed by…
4. ARRAY[1:10] has an upper bound of…
5. A 2D array is like…
6. Bubble sort compares…
7. Which file mode deletes existing contents?
8. Why store data in files?
9. A stack is…
10. A queue removes items from…
11. Overflow occurs when…
12. A circular queue…
13. A linked list node contains…
14. The free list in a linked list…
15. Which is an ADT?

Frequently asked questions

What is the difference between a stack and a queue?

A stack is Last In First Out, so items are added and removed at the top. A queue is First In First Out, so items are added at the rear and removed from the front.

What is a record data type?

A record is a user-defined data type that groups related fields of different data types under one identifier.

How do you read a text file in pseudocode?

Use OPENFILE for READ, then a WHILE NOT EOF loop with READFILE, and finally CLOSEFILE.

Was this page helpful?