CIE Computer Science Paper 2
CIE Computer Science Paper 2
Abstract data type (ADT) – a collection of data and a set of operations on that
data.
Stack – a list containing several items operating on the last in, first out (LIFO)
principle.
Queue – a list containing several items operating on the first in, first out (FIFO)
principle.
Linked list – a list containing several items in which each item in the list points
to the next item in the list.
Uses
Stacks- main memory management, expression evaluation, undo operation and
browser back, the return address to the main program during procedure calls
Queue- Management of files sent to a printer, Buffers used with keyboards,
Scheduling
Linked list- using array to implement a binary tree
Key features
Stack-
Queue
● Each queue element contains one data item
● A Pointer to the front of the queue
● A Pointer to the end of the queue
● Data is added at back
● works on a FIFO basis
● May be circular
Linked list
● Each node contains data and a pointer to the next node
● A Pointer to the start of the list
● Last node in the list has a null pointer
● Data may be added / removed by manipulating pointers (not moving
data)
● Nodes are traversed in a specific sequence
● Unused nodes are stored on a free list // A free-list pointer to the free
list
Implementing a stack
. Declare a (1D) array of data type
. The number of elements in that array corresponds to the size of the
required stack
. Declare an integer / variable for StackPointer
. Declare an integer / variable for the size of the stack
. Use the StackPointer as an index to the array
. Pointers and variables initialised to indicate empty stack
. Store each item on the stack as one array element
. Push and Pop routines need to check for full or empty conditions
Implementing a queue
. Declare a 1D array
. Declare and initialise front and rear pointers
. Items are added to the rear and read from the front
. Once items are added to the last node in the array and queue is not
full, rear become 1
Implementing a linked list
. Define a record type with fields for data and pointer
. Declare one (1D) array of the defined record type
. Declare an integer / variable for StartPointer
. Define appropriate value for null pointer
. Declare an integer / variable for FreeList pointer
.
Features of IDE
Coding
● Context-sensitive help
● Syntax checking (on entry)
● Automatic indentation
● Type checking (Parameter checking)
● PrettyPrinting
● Highlight structure blocks (e.g. selection, iteration)
● Highlight any undeclared variables
● Highlight any unassigned variables
Functions and Procedures - a set of statements that can be grouped together
and easily called
in a program whenever required, rather than repeating all of the statements
each time.