Data Types And Structures Flashcards
Setting up a maze
SET maze[0][1] TO 1 SET maze [1][1] TO 2 SET maze [1][2] TO 5 SET maze [2][3] TO 3 SET maze [3][4] TO 7....etc
Moving from room to room
Procedure change
2D Arrays - Printing contents
FOR row from 0 TO 8 DO FOR column from 0 TO 3 DO SEND maze[row][column] TO display END FOR END FOR
Advantages of a linked list
Is a dynamic data structure, meaning that its size is not fixed and can grow and shrink during execution
A linked list is flexible as the order of its items can be changed by moving links between data and not the actual data itself
Is more memory efficient than an array because it only needs to be as large as the number of items to be stored
Disadvantages of a linked list
It is not possible to identify a specific item directly using its index such as in an array
Instead you have to walk through the list from beginning to end
Linked lists are useful for implementation on
Dynamic data structures such as Queues and stacks
Setting up a linked list
Procedure Setuplist
DECLARE data INTEGER initially
DECLARE head pointer initially NUL
END Procedure
Inserting a new node to a linked list
PROCEDURE newnode (Integer data, Pointer next) IF head = NUL THEN
Next = NUL
ELSE
Next = NUL
END IF
END PROCEDURE
Deleting a node from a linked list
Procedure deletenode (Integer data)
IF head = NUL THEN
SEND list is empty TO display
ELSE IF
THEN
END IF
Linked lists are useful for implementation on
Dynamic data structures such as Queues and stacks
Setting up a linked list
Procedure Setuplist
DECLARE data INTEGER initially
DECLARE head pointer initially NUL
END Procedure
Inserting a new node to a linked list
PROCEDURE newnode (Integer data, Pointer next) IF head = NUL THEN
Next = NUL
ELSE
Next = NUL
END IF
END PROCEDURE
Deleting a node from a linked list
Procedure deletenode (Integer data)
IF head = NUL THEN
SEND list is empty TO display
ELSE IF
THEN
END IF