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
stack
a list of several items operating by last in first out - items can be added (push) and removed (pop) - first added is last removed
has a top of stack pointer
queue
a list of several items operating on first in first out - items can be added (enqueue) and removed (dequeue)
linked list
a list of several items where each item points to the next item
contains pointers and nodes
start pointer points to first element
null pointer signals end eg points to -1
file opening mode
READ
WRITE
APPRND - adds data to end
how to add/ delete stack
POP from the top of the stack
and PUSH to add to the top of stack
how to add/ delete queue
add items to the end (enqueue)
remove items from the front (dequeue)
hwo to add / delete linked list
doen need to change the position of any values just edit their pointers
declaring a variable of a record type
DECLARE <variable> : <recordtype>
eg DECLARE bibi : person
bibi.name <- “bibi”
bibi.age <- 17</recordtype></variable>