10 - data types and structures Flashcards
data type
a classification attributed to an item of data, which determines the types of value it can take and how it can be used
record
a composite data type
comprising several related items that may be of different data types
composite data type
a data type constructed using several of the basic data types available in a particular programming language
array
a data structure containing several elements of the same data type
position of each element if found using the index
the first index is the lower bound and the last is the upper
can be 1D or 2D
basic/ primitive data types
can be identified by commands in programming languages
boolean
character
date
integer
real
string
record data type in pseudocode
TYPE
<typename>
DECLARE <identifier> : <data>
END TYPE
</data></identifier></typename>
1D array pseudocode
is like a list
DECLARE <identifier> : ARRAY[LB:UB] OF <data></data></identifier>
2D arrays pseudocode
is like a table with rows and columns
DECLARE <identifier> : ARRAY[LB:UB, LB:UB] OF <data></data></identifier>
linear search
searches every item in order from the lower bound to the upper
linear search pseudocode
INPUT item
foudn <- FALSE
index <- 0
WHILE found = FALSE AND index<= LEN(array)
IF item = array[index]
found = TRUE
index = index + 1
IF found
OUTPUT ‘item found’
bubble sort pseudocode
upper = LEN(array)
WHILE swap = FALSE AND upper >0
FOR i <- 0 TO upper - 1
swap = FALSE
IF array[i] > array[i+1]
temp = array[i]
array[i] = array[i +1]
array[i + 1] = temp
swap = TRUE
upper <- upper -1
bubble sort
each element is compared with the next and swapped if in the wrong order
this is repeated until the end is reached
this is repeated until the whole list is ordered
files
store data
identified by a filename
contain a sequence of characters
can include an end of line character that enables the file to be read from and written to
file pseudocode
open file
OPEN <filename> FOR <filemode>
read/ write
READFILE <filename>, <variable>
WRITEFILE ''
to see if the file is at teh end
EOF(<filename>)
when the files not being used
CLOSEFILE < filename ></filename></variable></filename></filemode></filename>
ADT
abstract data type
- collect of data and set of operations on that data
eg stack queue linked list