Professional Documents
Culture Documents
Abstraction 9618
Abstraction 9618
Abstraction
1
2/15/2021
2
2/15/2021
Person.Name ← "Fred"
Person.NumberOfSiblings ← 3
Person.IsFullTimeStudent ← TRUE
To output a field of a record:
OUTPUT Person.Name
3
2/15/2021
4
2/15/2021
ADT – TREE
5
2/15/2021
6
2/15/2021
7
2/15/2021
8
2/15/2021
9
2/15/2021
10
2/15/2021
Start Null
Pointer Pointers
11
2/15/2021
2. Paul added to the list. Its pointer is null to also mark it as the last node. The start pointer also points to Paul
An example sequence of loading the list might be to INSERT Paul, Ali,
3. Ali is added. Now the start pointer needs to point to Ali since this name comes before Paul alphabetically Hameed and Sajid in that order. Let's examine how the INSERT
4.Sajid is added. So the Paul pointer now points to Sajid and Sajid is given a Null pointer. algorithm is used.
5. Hameed is added. The Ali pointer is changed to point to Hameed and the Hameed pointer now points to Paul.
12
2/15/2021
Deleting a node from a linked list Deleting a node from a linked list
Starting with the first node pointed to by the start pointer • Case 2:
Is this the node to be removed? The node to be removed is an intermediate one Examine the next node by
using the node pointers to move from node to node until the correct node is
• Case 1: identified
The node to be removed is the first one. Adjust the start pointer to Node found
point to the next node Copy the pointer of the removed node into temporary memory
Remove the original node Remove the node from the list and mark the memory it was using as free
once more
Mark the memory it used as free once more
Update the previous node's pointer with the address held in temporary
Task complete memory
Task complete
Binary Tree
Deleting a node from a linked list
• Case 3:
It is the last node to be removed
• Remove the last node from the list
• Mark the prior node with a null pointer
• Mark the memory the deleted node used as free once more.
• Task complete
• Case 4:
• Node cannot be found
• Return an error message to the calling code
• Task complete
13
2/15/2021
For numbers, this means the left sub-tree contains numbers less than the
root and the right sub-tree contains numbers greater than the root. For
words, as might be in a sorted dictionary, the order is alphabetic.
14
2/15/2021
15
2/15/2021
16
2/15/2021
17
2/15/2021
18
2/15/2021
19
2/15/2021
20