Traversals of Linked Lists Preorder BST Traversal Postorder BST Traversal Miscellaneous BST Traversals Depth First vs Breadth First Array Traversals - PowerPoint PPT Presentation

About This Presentation
Title:

Traversals of Linked Lists Preorder BST Traversal Postorder BST Traversal Miscellaneous BST Traversals Depth First vs Breadth First Array Traversals

Description:

Iterative (linear structures) Visiting Every Element ... Iterative Traversal Template. procedure Traverse (cur iot in Ptr toa Node) ... – PowerPoint PPT presentation

Number of Views:49
Avg rating:3.0/5.0
Slides: 235
Provided by: ccGa
Category:

less

Transcript and Presenter's Notes

Title: Traversals of Linked Lists Preorder BST Traversal Postorder BST Traversal Miscellaneous BST Traversals Depth First vs Breadth First Array Traversals


1
Traversals of Linked ListsPreorder BST
TraversalPostorder BST TraversalMiscellaneous
BST TraversalsDepth First vs Breadth FirstArray
Traversals
Lecture 14
2
Traversals of Linked Lists
3
The Scenario
  • We need to visit each element in the linked list.
  • At each element, we do some work.
  • Well stop when we reach the end of the list.
  • Examples
  • Printing all elements
  • Updating/changing the data of all elements

4
Traversals
  • A traversal visits every element in a collection.
  • Two forms
  • Recursive
  • Iterative (linear structures)

5
Visiting Every Element
//
head
48
17
142
  • Regardless of whether we use iteration or
    recursion, we continue until we reach the end
    (NIL).

6
Dont De-reference NIL
  • We must make sure we dont de-reference (follow)
    the NIL pointer.
  • To do this, always test to see if the pointer is
    NIL.
  • If so, we cant use the operator

head
//
Cant follow head! (i.e. head doesnt work!)
7
Testing for NIL
  • Always test for NIL at the beginning of your
    loop.
  • Your exitif statement must appear at the top
  • Always test for NIL at the beginning of your
    recursive module.
  • Your terminating condition must appear at the
    top of your module

8
Iterative Traversal Template
  • procedure Traverse (cur iot in Ptr toa Node)
  • // Purpose call Do_Something on each element
  • // Precondition none
  • // Postcondition Do_Something on each element
  • loop
  • exitif( cur NIL )
  • Do_Something( cur.data )
  • cur lt- cur.next
  • endloop
  • endprocedure // Traverse

9
An Iterative Traversal Example
  • procedure Print_List(cur iot in Ptr toa Node)
  • loop
  • exitif (cur NIL)
  • print(cur.data)
  • cur lt- cur.next
  • endloop
  • endprocedure //Print_List

Called via Print_List(list_head)
cur
list_head
17
42
4
10
An Iterative Traversal Example
  • procedure Print_List(cur iot in Ptr toa Node)
  • loop
  • exitif (cur NIL)
  • print(cur.data)
  • cur lt- cur.next
  • endloop
  • endprocedure //Print_List

cur
list_head
17
42
4
11
An Iterative Traversal Example
  • procedure Print_List(cur iot in Ptr toa Node)
  • loop
  • exitif (cur NIL)
  • print(cur.data)
  • cur lt- cur.next
  • endloop
  • endprocedure //Print_List

4
cur
list_head
17
42
4
12
An Iterative Traversal Example
  • procedure Print_List(cur iot in Ptr toa Node)
  • loop
  • exitif (cur NIL)
  • print(cur.data)
  • cur lt- cur.next
  • endloop
  • endprocedure //Print_List

4
cur
list_head
17
42
4
13
An Iterative Traversal Example
  • procedure Print_List(cur iot in Ptr toa Node)
  • loop
  • exitif (cur NIL)
  • print(cur.data)
  • cur lt- cur.next
  • endloop
  • endprocedure //Print_List

4
cur
list_head
17
42
4
14
An Iterative Traversal Example
  • procedure Print_List(cur iot in Ptr toa Node)
  • loop
  • exitif (cur NIL)
  • print(cur.data)
  • cur lt- cur.next
  • endloop
  • endprocedure //Print_List

4
cur
list_head
17
42
4
15
An Iterative Traversal Example
  • procedure Print_List(cur iot in Ptr toa Node)
  • loop
  • exitif (cur NIL)
  • print(cur.data)
  • cur lt- cur.next
  • endloop
  • endprocedure //Print_List

4 17
cur
list_head
17
42
4
16
An Iterative Traversal Example
  • procedure Print_List(cur iot in Ptr toa Node)
  • loop
  • exitif (cur NIL)
  • print(cur.data)
  • cur lt- cur.next
  • endloop
  • endprocedure //Print_List

4 17
cur
list_head
17
42
4
17
An Iterative Traversal Example
  • procedure Print_List(cur iot in Ptr toa Node)
  • loop
  • exitif (cur NIL)
  • print(cur.data)
  • cur lt- cur.next
  • endloop
  • endprocedure //Print_List

4 17
cur
list_head
17
42
4
18
An Iterative Traversal Example
  • procedure Print_List(cur iot in Ptr toa Node)
  • loop
  • exitif (cur NIL)
  • print(cur.data)
  • cur lt- cur.next
  • endloop
  • endprocedure //Print_List

4 17
cur
list_head
17
42
4
19
An Iterative Traversal Example
  • procedure Print_List(cur iot in Ptr toa Node)
  • loop
  • exitif (cur NIL)
  • print(cur.data)
  • cur lt- cur.next
  • endloop
  • endprocedure //Print_List

4 17 42
cur
list_head
17
42
4
20
An Iterative Traversal Example
  • procedure Print_List(cur iot in Ptr toa Node)
  • loop
  • exitif (cur NIL)
  • print(cur.data)
  • cur lt- cur.next
  • endloop
  • endprocedure //Print_List

4 17 42
cur
list_head
17
42
4
21
An Iterative Traversal Example
  • procedure Print_List(cur iot in Ptr toa Node)
  • loop
  • exitif (cur NIL)
  • print(cur.data)
  • cur lt- cur.next
  • endloop
  • endprocedure //Print_List

4 17 42
cur
list_head
17
42
4
22
An Iterative Traversal Example
  • procedure Print_List(cur iot in Ptr toa Node)
  • loop
  • exitif (cur NIL)
  • print(cur.data)
  • cur lt- cur.next
  • endloop
  • endprocedure //Print_List

4 17 42
cur
list_head
17
42
4
23
Recursive Traversal Template
  • procedure Traverse (cur iot in Ptr toa Node)
  • // Purpose call Do_Something on each element
  • // Precondition none
  • // Postcondition Do_Something on each element
  • if (cur ltgt NIL) then
  • Do_Something( cur.data )
  • Traverse( cur.next )
  • endif
  • endprocedure // Traverse

24
A Recursive Traversal Example
  • procedure Print_List(cur iot in Ptr toa Node)
  • if (cur ltgt NIL) then
  • print(cur.data)
  • Print_List(cur.next)
  • endif
  • endprocedure //Print_List

Called via Print_List(list_head)
cur
list_head
17
42
4
You already know how to do this...
25
A Loophole in Parameter Protection
  • If a pointer is an in parameter, the pointer
    cannot be changed.
  • But, anything to which the pointer points may be
    changed.
  • Thus, giving access to a list means giving
    ability to make changes to it you cannot protect
    against this.

26
An Example
  • procedure DestroyList (cur iot in Ptr toa Node)
  • if (cur ltgt nil) then
  • cur.data lt- -1
  • DestroyList(cur.next)
  • endif
  • endprocedure // DestroyList

//
head
48
17
142
27
Another Example
  • procedure DestroyList (cur iot in Ptr toa Node)
  • cur.next lt- NIL
  • endprocedure // DestroyList

//
head
48
17
142
28
Summary
  • Traversals involve visiting every element
  • Recursion or iteration
  • Stop when you reach NIL
  • Make sure to not de-reference NIL
  • Be aware that passing a pointer to a module via
    an IN parameter allows the module to modify the
    entire list.

29
Questions?
30
Traversing a Binary Search Tree (BST)Pre-Order
31
Outline of Pre-Order Traversal
  • Three principle steps
  • Do work (Current)
  • Traverse Left
  • Traverse Right
  • Work can be anything
  • Separate work from traversal

32
  • Traverse the tree Pre-order
  • Visit the current and do work
  • Visit the trees left sub-tree
  • Visit right sub-tree

33
Pre-Order Traversal Procedure
  • procedure Pre_Order(cur iot in Ptr toa Tree_Node)
  • // Purpose perform pre-order traversal, call
  • // DoWhatever for each node
  • // Preconditions cur points to a binary tree
  • // Postcondition DoWhatever will be performed
  • // on each tree node in pre-order order
  • if( cur ltgt NIL ) then
  • Do_Whatever( cur.data )
  • Pre_Order( cur.left_child )
  • Pre_Order( cur.right_child )
  • endif
  • endprocedure // Pre_Order

34
Proc PreOrderPrint(pointer) pointer NOT NIL?
print(data) PreOrderPrint(left child)
PreOrderPrint(right child)
root
P
L
R
35
Questions?
36
Traversing a Binary Search Tree (BST)Post-Order
37
Outline of Post-Order Traversal
  • Three principle steps
  • Traverse Left
  • Traverse Right
  • Do work (Current)
  • Work can be anything
  • Separate work from traversal

38
  • Traverse the tree Post order
  • Visit the trees left sub-tree
  • Visit right sub-tree
  • Visit the current and do work

39
Post-Order Traversal Procedure
  • procedure Post_Order(cur iot in Ptr toa
    Tree_Node)
  • // Purpose perform post-order traversal, call
  • // DoWhatever for each node
  • // Preconditions cur points to a binary tree
  • // Postcondition DoWhatever will be performed
  • // on each tree node in post-order order
  • if( cur ltgt NIL ) then
  • Post_Order( cur.left_child )
  • Post_Order( cur.right_child )
  • Do_Whatever( cur.data )
  • endif
  • endprocedure // Post_Order

40
Proc PostOrderPrint(pointer) pointer NOT NIL?
PostOrderPrint(left child) PostOrderPrint(right
child) print(data)
root
L
R
P
41
Questions?
42
Miscellaneous BST Traversals
43
Miscellaneous Traversals
  • Defined Traversals
  • In-order L C R
  • Pre-order C L R
  • Post-order L R C
  • Other Possibilities
  • R C L
  • C R L
  • R L C

44
Proc MiscTraverse(pointer) pointer NOT NIL?
print(data) MiscTraverse(right child)
MiscTraverse(left child)
root
P
R
L
45
Proc MiscTraverse(pointer) pointer NOT NIL?
print(data) MiscTraverse(right child)
MiscTraverse(left child)
root
P
R
L
46
Proc MiscTraverse(pointer) pointer NOT NIL?
print(data) MiscTraverse(right child)
MiscTraverse(left child)
root
P
P
R
L
Output 22
47
Proc MiscTraverse(pointer) pointer NOT NIL?
print(data) MiscTraverse(right child)
MiscTraverse(left child)
root
P
P
R
R
L
Output 22
48
Proc MiscTraverse(pointer) pointer NOT NIL?
print(data) MiscTraverse(right child)
MiscTraverse(left child)
root
P
P
R
R
L
P
Output 22 67
49
Proc MiscTraverse(pointer) pointer NOT NIL?
print(data) MiscTraverse(right child)
MiscTraverse(left child)
root
P
P
R
R
L
P
Output 22 67
R
50
Proc MiscTraverse(pointer) pointer NOT NIL?
print(data) MiscTraverse(right child)
MiscTraverse(left child)
root
P
P
R
R
L
P
Output 22 67 94
R
P
51
Proc MiscTraverse(pointer) pointer NOT NIL?
print(data) MiscTraverse(right child)
MiscTraverse(left child)
root
P
P
R
R
L
P
Output 22 67 94
R
P
R
52
Proc MiscTraverse(pointer) pointer NOT NIL?
print(data) MiscTraverse(right child)
MiscTraverse(left child)
root
P
P
R
R
L
P
Output 22 67 94 97
R
P
R
P
53
Proc MiscTraverse(pointer) pointer NOT NIL?
print(data) MiscTraverse(right child)
MiscTraverse(left child)
root
P
P
R
R
L
P
Output 22 67 94 97
R
P
R
P
R
54
Proc MiscTraverse(pointer) pointer NOT NIL?
print(data) MiscTraverse(right child)
MiscTraverse(left child)
root
P
P
R
R
L
L
P
P
Output 22 67 94 97 36 44 9 14 3 7 1
R
R
L
L
P
P
P
P
R
R
R
R
L
L
L
L
P
P
P
P
R
R
R
R
L
L
L
L
55
Questions?
56
Depth First vs. Breadth First Traversal
57
Depth vs. Breadth First Traversals
  • Depth First Traversals
  • Go down (deep)
  • In-, Pre-, Post-order
  • Breadth First Traversals
  • Go across (shallow)
  • Require a queue to help

58
Depth-First Traversal
root
59
Breadth-First Traversal
root
60
Depth First Traversal (In-Order)
  • Procedure DFT
  • (current isoftype in Ptr toa Node)
  • // In order DFT
  • if(current ltgt NIL) then
  • DFT(current.left)
  • print(current.data)
  • DFT(Current.right)
  • endif
  • endprocedure

61
Depth First Traversal (Pre-Order)
  • Procedure DFT
  • (current isoftype in Ptr toa Node)
  • // In order DFT
  • if(current ltgt NIL) then
  • DFT(current.left)
  • print(current.data)
  • DFT(Current.right)
  • endif
  • endprocedure

Move this here to make a Preorder DFT
62
Depth First Traversal (Post-Order)
  • Procedure DFT
  • (current isoftype in Ptr toa Node)
  • // In order DFT
  • if(current ltgt NIL) then
  • DFT(current.left)
  • print(current.data)
  • DFT(Current.right)
  • endif
  • endprocedure

Move this here to make a Postorder DFT
63
Proc DFT(pointer) pointer NOT NIL? DFT(left
child) print(data) DFT(right child)
root
We have already seen these!
64
Breadth-First Traversal
  • Requires a queue to maintain which nodes to visit
    next.
  • Enqueue the root pointer
  • Loop until no elements in the queue
  • Dequeue(current)
  • Enqueue currents left and right children
  • Do work at current

65
Breadth-First Traversal
LB
  • Procedure BFT(root isoftype in Ptr toa Node)
  • Q isoftype Queue
  • Initialize(Q)
  • temp isoftype Ptr toa Node
  • OK isoftype Boolean
  • enqueue(Q, root)
  • // continued

66
Breadth-First Traversal
LB
  • loop
  • dequeue(temp, OK, Q)
  • exitif(NOT OK)
  • if(temp.left ltgt NIL) then
  • enqueue(temp.left, Q))
  • endif
  • if(temp.right ltgt NIL) then
  • enqueue(temp.right, Q)
  • endif
  • print(temp.data) // processing node
  • endloop
  • endprocedure

67
  • Enqueue(root)
  • loop
  • exitif Q empty
  • dequeue(aNode)
  • enqueue(children)
  • print(data)
  • endloop

root
Q
aNode
68
  • Enqueue(root)
  • loop
  • exitif Q empty
  • dequeue(aNode)
  • enqueue(children)
  • print(data)
  • endloop

root
Q22
aNode
69
  • Enqueue(root)
  • loop
  • exitif Q empty
  • dequeue(aNode)
  • enqueue(children)
  • print(data)
  • endloop

root
Q22
aNode
70
  • Enqueue(root)
  • loop
  • exitif Q empty
  • dequeue(aNode)
  • enqueue(children)
  • print(aNode.data)
  • endloop

root
Q
aNode22
71
  • Enqueue(root)
  • loop
  • exitif Q empty
  • dequeue(aNode)
  • enqueue(children)
  • print(aNode.data)
  • endloop

root
Q9 67
aNode22
72
  • Enqueue(root)
  • loop
  • exitif Q empty
  • dequeue(aNode)
  • enqueue(children)
  • print(aNode.data)
  • endloop

root
Q9 67
aNode22
73
  • Enqueue(root)
  • loop
  • exitif Q empty
  • dequeue(aNode)
  • enqueue(children)
  • print(aNode.data)
  • endloop

root
Q9 67
aNode22
74
  • Enqueue(root)
  • loop
  • exitif Q empty
  • dequeue(aNode)
  • enqueue(children)
  • print(aNode.data)
  • endloop

root
Q67
aNode9
75
  • Enqueue(root)
  • loop
  • exitif Q empty
  • dequeue(aNode)
  • enqueue(children)
  • print(aNode.data)
  • endloop

root
Q67 3 14
aNode9
76
  • Enqueue(root)
  • loop
  • exitif Q empty
  • dequeue(aNode)
  • enqueue(children)
  • print(aNode.data)
  • endloop

root
Q67 3 14
aNode9
77
  • Enqueue(root)
  • loop
  • exitif Q empty
  • dequeue(aNode)
  • enqueue(children)
  • print(aNode.data)
  • endloop

root
Q67 3 14
aNode9
78
  • Enqueue(root)
  • loop
  • exitif Q empty
  • dequeue(aNode)
  • enqueue(children)
  • print(aNode.data)
  • endloop

root
Q3 14
aNode67
79
  • Enqueue(root)
  • loop
  • exitif Q empty
  • dequeue(aNode)
  • enqueue(children)
  • print(aNode.data)
  • endloop

root
Q3 14 36 94
aNode67
80
  • Enqueue(root)
  • loop
  • exitif Q empty
  • dequeue(aNode)
  • enqueue(children)
  • print(aNode.data)
  • endloop

root
Q3 14 36 94
aNode67
81
  • Enqueue(root)
  • loop
  • exitif Q empty
  • dequeue(aNode)
  • enqueue(children)
  • print(aNode.data)
  • endloop

root
Q3 14 36 94
aNode67
82
  • Enqueue(root)
  • loop
  • exitif Q empty
  • dequeue(aNode)
  • enqueue(children)
  • print(aNode.data)
  • endloop

root
Q14 36 94
aNode3
83
  • Enqueue(root)
  • loop
  • exitif Q empty
  • dequeue(aNode)
  • enqueue(children)
  • print(aNode.data)
  • endloop

root
Q14 36 94 1 7
aNode3
84
  • Enqueue(root)
  • loop
  • exitif Q empty
  • dequeue(aNode)
  • enqueue(children)
  • print(aNode.data)
  • endloop

root
Q14 36 94 1 7
aNode3
85
  • Enqueue(root)
  • loop
  • exitif Q empty
  • dequeue(aNode)
  • enqueue(children)
  • print(aNode.data)
  • endloop

root
Q14 36 94 1 7
aNode3
86
  • Enqueue(root)
  • loop
  • exitif Q empty
  • dequeue(aNode)
  • enqueue(children)
  • print(aNode.data)
  • endloop

root
Q36 94 1 7
aNode14
87
  • Enqueue(root)
  • loop
  • exitif Q empty
  • dequeue(aNode)
  • enqueue(children)
  • print(aNode.data)
  • endloop

root
Q36 94 1 7
aNode14
88
  • Enqueue(root)
  • loop
  • exitif Q empty
  • dequeue(aNode)
  • enqueue(children)
  • print(aNode.data)
  • endloop

root
Q36 94 1 7
aNode14
89
  • Enqueue(root)
  • loop
  • exitif Q empty
  • dequeue(aNode)
  • enqueue(children)
  • print(aNode.data)
  • endloop

root
Q36 94 1 7
aNode14
90
  • Enqueue(root)
  • loop
  • exitif Q empty
  • dequeue(aNode)
  • enqueue(children)
  • print(aNode.data)
  • endloop

root
Q94 1 7
aNode36
91
  • Enqueue(root)
  • loop
  • exitif Q empty
  • dequeue(aNode)
  • enqueue(children)
  • print(aNode.data)
  • endloop

root
Q94 1 7 44
aNode36
92
  • Enqueue(root)
  • loop
  • exitif Q empty
  • dequeue(aNode)
  • enqueue(children)
  • print(aNode.data)
  • endloop

root
Q94 1 7 44
aNode36
93
  • Enqueue(root)
  • loop
  • exitif Q empty
  • dequeue(aNode)
  • enqueue(children)
  • print(aNode.data)
  • endloop

root
Q94 1 7 44
aNode36
94
  • Enqueue(root)
  • loop
  • exitif Q empty
  • dequeue(aNode)
  • enqueue(children)
  • print(aNode.data)
  • endloop

root
Q1 7 44
aNode94
95
  • Enqueue(root)
  • loop
  • exitif Q empty
  • dequeue(aNode)
  • enqueue(children)
  • print(aNode.data)
  • endloop

root
Q1 7 44 97
aNode94
96
  • Enqueue(root)
  • loop
  • exitif Q empty
  • dequeue(aNode)
  • enqueue(children)
  • print(aNode.data)
  • endloop

root
Q1 7 44 97
aNode94
97
  • Enqueue(root)
  • loop
  • exitif Q empty
  • dequeue(aNode)
  • enqueue(children)
  • print(aNode.data)
  • endloop

root
Q1 7 44 97
aNode94
98
  • Enqueue(root)
  • loop
  • exitif Q empty
  • dequeue(aNode)
  • enqueue(children)
  • print(aNode.data)
  • endloop

root
Q7 44 97
aNode1
99
  • Enqueue(root)
  • loop
  • exitif Q empty
  • dequeue(aNode)
  • enqueue(children)
  • print(aNode.data)
  • endloop

root
Q7 44 97
aNode1
100
  • Enqueue(root)
  • loop
  • exitif Q empty
  • dequeue(aNode)
  • enqueue(children)
  • print(aNode.data)
  • endloop

root
Q7 44 97
aNode1
101
  • Enqueue(root)
  • loop
  • exitif Q empty
  • dequeue(aNode)
  • enqueue(children)
  • print(aNode.data)
  • endloop

root
Q7 44 97
aNode1
102
  • Enqueue(root)
  • loop
  • exitif Q empty
  • dequeue(aNode)
  • enqueue(children)
  • print(aNode.data)
  • endloop

root
Q44 97
aNode7
103
  • Enqueue(root)
  • loop
  • exitif Q empty
  • dequeue(aNode)
  • enqueue(children)
  • print(aNode.data)
  • endloop

root
Q44 97
aNode7
104
  • Enqueue(root)
  • loop
  • exitif Q empty
  • dequeue(aNode)
  • enqueue(children)
  • print(aNode.data)
  • endloop

root
Q44 97
aNode7
105
  • Enqueue(root)
  • loop
  • exitif Q empty
  • dequeue(aNode)
  • enqueue(children)
  • print(aNode.data)
  • endloop

root
Q44 97
aNode7
106
  • Enqueue(root)
  • loop
  • exitif Q empty
  • dequeue(aNode)
  • enqueue(children)
  • print(aNode.data)
  • endloop

root
Q97
aNode44
107
  • Enqueue(root)
  • loop
  • exitif Q empty
  • dequeue(aNode)
  • enqueue(children)
  • print(aNode.data)
  • endloop

root
Q97
aNode44
108
  • Enqueue(root)
  • loop
  • exitif Q empty
  • dequeue(aNode)
  • enqueue(children)
  • print(aNode.data)
  • endloop

root
Q97
aNode44
109
  • Enqueue(root)
  • loop
  • exitif Q empty
  • dequeue(aNode)
  • enqueue(children)
  • print(aNode.data)
  • endloop

root
Q97
aNode44
110
  • Enqueue(root)
  • loop
  • exitif Q empty
  • dequeue(aNode)
  • enqueue(children)
  • print(aNode.data)
  • endloop

root
Q
aNode97
111
  • Enqueue(root)
  • loop
  • exitif Q empty
  • dequeue(aNode)
  • enqueue(children)
  • print(aNode.data)
  • endloop

root
Q
aNode97
112
  • Enqueue(root)
  • loop
  • exitif Q empty
  • dequeue(aNode)
  • enqueue(children)
  • print(aNode.data)
  • endloop

root
Q
aNode97
113
  • Enqueue(root)
  • loop
  • exitif Q empty
  • dequeue(aNode)
  • enqueue(children)
  • print(aNode.data)
  • endloop

root
Q
aNode97
114
Queuestions?
115
Traversals of Arrays
116
The Scenario
  • We need to visit each element in the array.
  • At each element, we do some work.
  • Well stop when we reach the end of the array
    (when we reach MAX).
  • Examples
  • Printing all elements
  • Updating/changing the data of all elements

117
Traversals
  • A traversal visits every element in a collection.
  • Two forms
  • Recursive
  • Iterative (linear structures)

118
Recursive Array Traversal Template
  • procedure RecursiveTraverse (i iot in num,
    NumArray iot in NumArrayType)
  • // Purpose call Do_Something on each element
  • // Precondition i 1 on first call
  • // Postcondition Do_Something on each element
  • if (i lt MAX) then
  • Do_Something(NumArrayi)
  • RecursiveTraverse (i1, NumArray)
  • endif
  • endprocedure

119
Recursive Array Traversal Example
  • procedure RecursiveTraverse (i iot in num,
    NumArray iot in NumArrayType)
  • // Pre i 1 on first call
  • if (i lt MAX) then
  • print(NumArrayi)
  • RecursiveTraverse (i1, NumArray)
  • endif
  • endprocedure

120
  • procedure RecursiveTraverse (i iot in num,
    NumArray iot in NumArrayType)
  • // Pre i 1 on first call
  • if (i lt MAX) then
  • print(NumArrayi)
  • RecursiveTraverse (i1, NumArray)
  • endif
  • endprocedure

i 1
NumArray
12
43
11
9
98
1 2 3 4 5
121
  • procedure RecursiveTraverse (i iot in num,
    NumArray iot in NumArrayType)
  • // Pre i 1 on first call
  • if (i lt MAX) then
  • print(NumArrayi)
  • RecursiveTraverse (i1, NumArray)
  • endif
  • endprocedure

i 1
12
12
43
11
9
98
NumArray
1 2 3 4 5
122
  • procedure RecursiveTraverse (i iot in num,
    NumArray iot in NumArrayType)
  • // Pre i 1 on first call
  • if (i lt MAX) then
  • print(NumArrayi)
  • RecursiveTraverse (i1, NumArray)
  • endif
  • endprocedure

i 1
12
12
43
11
9
98
NumArray
1 2 3 4 5
123
  • procedure RecursiveTraverse (i iot in num,
    NumArray iot in NumArrayType)
  • // Pre i 1 on first call
  • if (i lt MAX) then
  • print(NumArrayi)
  • RecursiveTraverse (i1, NumArray)
  • endif
  • endprocedure

procedure RecursiveTraverse (i iot in num,
NumArray iot in NumArrayType) // Pre i 1 on
first call if (i lt MAX) then
print(NumArrayi) RecursiveTraverse (i1,
NumArray) endif endprocedure
i 1
i 2
12
12
43
11
9
98
NumArray
1 2 3 4 5
124
  • procedure RecursiveTraverse (i iot in num,
    NumArray iot in NumArrayType)
  • // Pre i 1 on first call
  • if (i lt MAX) then
  • print(NumArrayi)
  • RecursiveTraverse (i1, NumArray)
  • endif
  • endprocedure

procedure RecursiveTraverse (i iot in num,
NumArray iot in NumArrayType) // Pre i 1 on
first call if (i lt MAX) then
print(NumArrayi) RecursiveTraverse (i1,
NumArray) endif endprocedure
i 1
i 2
12 43
12
43
11
9
98
NumArray
1 2 3 4 5
125
  • procedure RecursiveTraverse (i iot in num,
    NumArray iot in NumArrayType)
  • // Pre i 1 on first call
  • if (i lt MAX) then
  • print(NumArrayi)
  • RecursiveTraverse (i1, NumArray)
  • endif
  • endprocedure

procedure RecursiveTraverse (i iot in num,
NumArray iot in NumArrayType) // Pre i 1 on
first call if (i lt MAX) then
print(NumArrayi) RecursiveTraverse (i1,
NumArray) endif endprocedure
i 1
i 2
12 43
12
43
11
9
98
NumArray
1 2 3 4 5
126
  • procedure RecursiveTraverse (i iot in num,
    NumArray iot in NumArrayType)
  • // Pre i 1 on first call
  • if (i lt MAX) then
  • print(NumArrayi)
  • RecursiveTraverse (i1, NumArray)
  • endif
  • endprocedure

i 1
12 43
12
43
11
9
98
NumArray
1 2 3 4 5
127
  • procedure RecursiveTraverse (i iot in num,
    NumArray iot in NumArrayType)
  • // Pre i 1 on first call
  • if (i lt MAX) then
  • print(NumArrayi)
  • RecursiveTraverse (i1, NumArray)
  • endif
  • endprocedure

i 1
12 43 11
12
43
11
9
98
NumArray
1 2 3 4 5
128
  • procedure RecursiveTraverse (i iot in num,
    NumArray iot in NumArrayType)
  • // Pre i 1 on first call
  • if (i lt MAX) then
  • print(NumArrayi)
  • RecursiveTraverse (i1, NumArray)
  • endif
  • endprocedure

i 1
12 43 11
12
43
11
9
98
NumArray
1 2 3 4 5
129
  • procedure RecursiveTraverse (i iot in num,
    NumArray iot in NumArrayType)
  • // Pre i 1 on first call
  • if (i lt MAX) then
  • print(NumArrayi)
  • RecursiveTraverse (i1, NumArray)
  • endif
  • endprocedure

i 1
12 43 11
12
43
11
9
98
NumArray
1 2 3 4 5
130
  • procedure RecursiveTraverse (i iot in num,
    NumArray iot in NumArrayType)
  • // Pre i 1 on first call
  • if (i lt MAX) then
  • print(NumArrayi)
  • RecursiveTraverse (i1, NumArray)
  • endif
  • endprocedure

i 1
12 43 11 9
12
43
11
9
98
NumArray
1 2 3 4 5
131
  • procedure RecursiveTraverse (i iot in num,
    NumArray iot in NumArrayType)
  • // Pre i 1 on first call
  • if (i lt MAX) then
  • print(NumArrayi)
  • RecursiveTraverse (i1, NumArray)
  • endif
  • endprocedure

i 1
12 43 11 9
12
43
11
9
98
NumArray
1 2 3 4 5
132
  • procedure RecursiveTraverse (i iot in num,
    NumArray iot in NumArrayType)
  • // Pre i 1 on first call
  • if (i lt MAX) then
  • print(NumArrayi)
  • RecursiveTraverse (i1, NumArray)
  • endif
  • endprocedure

i 1
12 43 11 9
12
43
11
9
98
NumArray
1 2 3 4 5
133
  • procedure RecursiveTraverse (i iot in num,
    NumArray iot in NumArrayType)
  • // Pre i 1 on first call
  • if (i lt MAX) then
  • print(NumArrayi)
  • RecursiveTraverse (i1, NumArray)
  • endif
  • endprocedure

i 1
12 43 11 9 98
12
43
11
9
98
NumArray
1 2 3 4 5
134
  • procedure RecursiveTraverse (i iot in num,
    NumArray iot in NumArrayType)
  • // Pre i 1 on first call
  • if (i lt MAX) then
  • print(NumArrayi)
  • RecursiveTraverse (i1, NumArray)
  • endif
  • endprocedure

i 1
12 43 11 9 98
12
43
11
9
98
NumArray
1 2 3 4 5
135
  • procedure RecursiveTraverse (i iot in num,
    NumArray iot in NumArrayType)
  • // Pre i 1 on first call
  • if (i lt MAX) then
  • print(NumArrayi)
  • RecursiveTraverse (i1, NumArray)
  • endif
  • endprocedure

i 1
12 43 11 9 98
12
43
11
9
98
NumArray
1 2 3 4 5
136
  • procedure RecursiveTraverse (i iot in num,
    NumArray iot in NumArrayType)
  • // Pre i 1 on first call
  • if (i lt MAX) then
  • print(NumArrayi)
  • RecursiveTraverse (i1, NumArray)
  • endif
  • endprocedure

i 1
12 43 11 9 98
12
43
11
9
98
NumArray
1 2 3 4 5
137
  • procedure RecursiveTraverse (i iot in num,
    NumArray iot in NumArrayType)
  • // Pre i 1 on first call
  • if (i lt MAX) then
  • print(NumArrayi)
  • RecursiveTraverse (i1, NumArray)
  • endif
  • endprocedure

i 1
12 43 11 9 98
12
43
11
9
98
NumArray
1 2 3 4 5
138
  • procedure RecursiveTraverse (i iot in num,
    NumArray iot in NumArrayType)
  • // Pre i 1 on first call
  • if (i lt MAX) then
  • print(NumArrayi)
  • RecursiveTraverse (i1, NumArray)
  • endif
  • endprocedure

i 1
12 43 11 9 98
12
43
11
9
98
NumArray
1 2 3 4 5
139
  • procedure RecursiveTraverse (i iot in num,
    NumArray iot in NumArrayType)
  • // Pre i 1 on first call
  • if (i lt MAX) then
  • print(NumArrayi)
  • RecursiveTraverse (i1, NumArray)
  • endif
  • endprocedure

i 1
12 43 11 9 98
12
43
11
9
98
NumArray
1 2 3 4 5
140
  • procedure RecursiveTraverse (i iot in num,
    NumArray iot in NumArrayType)
  • // Pre i 1 on first call
  • if (i lt MAX) then
  • print(NumArrayi)
  • RecursiveTraverse (i1, NumArray)
  • endif
  • endprocedure

i 1
12 43 11 9 98
12
43
11
9
98
NumArray
1 2 3 4 5
141
Iterative Traversal Template
  • procedure Traverse (my_array iot in/out
    ArrayType)
  • // Purpose call Do_Something on each element
  • // Precondition none
  • // Postcondition Do_Something on each element
  • i isoftype Num
  • i lt- 1
  • loop
  • exitif( i gt MAX )
  • Do_Something( my_arrayi )
  • i lt- i 1
  • endloop
  • endprocedure // Traverse

142
An Iterative Traversal Example
Traverse the array and fill in every elementso
that the ith element contains the value i.
1
2
3
4
5
6
7
8
9
10
1 2 3 4 5 6 7 8 9
10
143
MAX is 10 Vec_max definesa Array1..MAX of
Num data isoftype Vec_max i isoftype Num i lt-
1 loop exitif(i gt MAX) datai lt- i i lt- i
1 endloop
144
MAX is 10 Vec_max definesa Array1..MAX of
Num data isoftype Vec_max i isoftype Num i lt-
1 loop exitif(i gt MAX) datai lt- i i lt- i
1 endloop
145
MAX is 10 Vec_max definesa Array1..MAX of
Num data isoftype Vec_max i isoftype Num i lt-
1 loop exitif(i gt MAX) datai lt- i i lt- i
1 endloop
data
1 2 3 4 5 6 7 8 9
10
146
MAX is 10 Vec_max definesa Array1..MAX of
Num data isoftype Vec_max i isoftype Num i lt-
1 loop exitif(i gt MAX) datai lt- i i lt- i
1 endloop
data
1 2 3 4 5 6 7 8 9
10

i
147
MAX is 10 Vec_max definesa Array1..MAX of
Num data isoftype Vec_max i isoftype Num i lt-
1 loop exitif(i gt MAX) datai lt- i i lt- i
1 endloop
data
1 2 3 4 5 6 7 8 9
10
1
i
148
MAX is 10 Vec_max definesa Array1..MAX of
Num data isoftype Vec_max i isoftype Num i lt-
1 loop exitif(i gt MAX) datai lt- i i lt- i
1 endloop
data
1 2 3 4 5 6 7 8 9
10
1
i
149
MAX is 10 Vec_max definesa Array1..MAX of
Num data isoftype Vec_max i isoftype Num i lt-
1 loop exitif(i gt MAX) datai lt- i i lt- i
1 endloop
data
1 2 3 4 5 6 7 8 9
10
1
i
150
MAX is 10 Vec_max definesa Array1..MAX of
Num data isoftype Vec_max i isoftype Num i lt-
1 loop exitif(i gt MAX) datai lt- i i lt- i
1 endloop
data
1 2 3 4 5 6 7 8 9
10
1
i
151
MAX is 10 Vec_max definesa Array1..MAX of
Num data isoftype Vec_max i isoftype Num i lt-
1 loop exitif(i gt MAX) datai lt- i i lt- i
1 endloop
data
1 2 3 4 5 6 7 8 9
10
2
i
152
MAX is 10 Vec_max definesa Array1..MAX of
Num data isoftype Vec_max i isoftype Num i lt-
1 loop exitif(i gt MAX) datai lt- i i lt- i
1 endloop
data
1 2 3 4 5 6 7 8 9
10
2
i
153
MAX is 10 Vec_max definesa Array1..MAX of
Num data isoftype Vec_max i isoftype Num i lt-
1 loop exitif(i gt MAX) datai lt- i i lt- i
1 endloop
data
1 2 3 4 5 6 7 8 9
10
2
i
154
MAX is 10 Vec_max definesa Array1..MAX of
Num data isoftype Vec_max i isoftype Num i lt-
1 loop exitif(i gt MAX) datai lt- i i lt- i
1 endloop
data
1 2 3 4 5 6 7 8 9
10
2
i
155
MAX is 10 Vec_max definesa Array1..MAX of
Num data isoftype Vec_max i isoftype Num i lt-
1 loop exitif(i gt MAX) datai lt- i i lt- i
1 endloop
data
1 2 3 4 5 6 7 8 9
10
2
i
156
MAX is 10 Vec_max definesa Array1..MAX of
Num data isoftype Vec_max i isoftype Num i lt-
1 loop exitif(i gt MAX) datai lt- i i lt- i
1 endloop
data
1 2 3 4 5 6 7 8 9
10
3
i
157
MAX is 10 Vec_max definesa Array1..MAX of
Num data isoftype Vec_max i isoftype Num i lt-
1 loop exitif(i gt MAX) datai lt- i i lt- i
1 endloop
data
1 2 3 4 5 6 7 8 9
10
3
i
158
MAX is 10 Vec_max definesa Array1..MAX of
Num data isoftype Vec_max i isoftype Num i lt-
1 loop exitif(i gt MAX) datai lt- i i lt- i
1 endloop
data
1 2 3 4 5 6 7 8 9
10
3
i
159
MAX is 10 Vec_max definesa Array1..MAX of
Num data isoftype Vec_max i isoftype Num i lt-
1 loop exitif(i gt MAX) datai lt- i i lt- i
1 endloop
data
1 2 3 4 5 6 7 8 9
10
3
i
160
MAX is 10 Vec_max definesa Array1..MAX of
Num data isoftype Vec_max i isoftype Num i lt-
1 loop exitif(i gt MAX) datai lt- i i lt- i
1 endloop
data
1 2 3 4 5 6 7 8 9
10
3
i
161
MAX is 10 Vec_max definesa Array1..MAX of
Num data isoftype Vec_max i isoftype Num i lt-
1 loop exitif(i gt MAX) datai lt- i i lt- i
1 endloop
data
1 2 3 4 5 6 7 8 9
10
4
i
162
MAX is 10 Vec_max definesa Array1..MAX of
Num data isoftype Vec_max i isoftype Num i lt-
1 loop exitif(i gt MAX) datai lt- i i lt- i
1 endloop
data
1 2 3 4 5 6 7 8 9
10
4
i
163
MAX is 10 Vec_max definesa Array1..MAX of
Num data isoftype Vec_max i isoftype Num i lt-
1 loop exitif(i gt MAX) datai lt- i i lt- i
1 endloop
data
1 2 3 4 5 6 7 8 9
10
4
i
164
MAX is 10 Vec_max definesa Array1..MAX of
Num data isoftype Vec_max i isoftype Num i lt-
1 loop exitif(i gt MAX) datai lt- i i lt- i
1 endloop
data
1 2 3 4 5 6 7 8 9
10
5
i
165
MAX is 10 Vec_max definesa Array1..MAX of
Num data isoftype Vec_max i isoftype Num i lt-
1 loop exitif(i gt MAX) datai lt- i i lt- i
1 endloop
data
1 2 3 4 5 6 7 8 9
10
6
i
166
MAX is 10 Vec_max definesa Array1..MAX of
Num data isoftype Vec_max i isoftype Num i lt-
1 loop exitif(i gt MAX) datai lt- i i lt- i
1 endloop
data
1 2 3 4 5 6 7 8 9
10
7
i
167
MAX is 10 Vec_max definesa Array1..MAX of
Num data isoftype Vec_max i isoftype Num i lt-
1 loop exitif(i gt MAX) datai lt- i i lt- i
1 endloop
data
1 2 3 4 5 6 7 8 9
10
8
i
168
MAX is 10 Vec_max definesa Array1..MAX of
Num data isoftype Vec_max i isoftype Num i lt-
1 loop exitif(i gt MAX) datai lt- i i lt- i
1 endloop
data
1 2 3 4 5 6 7 8 9
10
9
i
169
MAX is 10 Vec_max definesa Array1..MAX of
Num data isoftype Vec_max i isoftype Num i lt-
1 loop exitif(i gt MAX) datai lt- i i lt- i
1 endloop
data
1 2 3 4 5 6 7 8 9
10
9
i
170
MAX is 10 Vec_max definesa Array1..MAX of
Num data isoftype Vec_max i isoftype Num i lt-
1 loop exitif(i gt MAX) datai lt- i i lt- i
1 endloop
data
1 2 3 4 5 6 7 8 9
10
10
i
171
MAX is 10 Vec_max definesa Array1..MAX of
Num data isoftype Vec_max i isoftype Num i lt-
1 loop exitif(i gt MAX) datai lt- i i lt- i
1 endloop
data
1 2 3 4 5 6 7 8 9
10
10
i
172
MAX is 10 Vec_max definesa Array1..MAX of
Num data isoftype Vec_max i isoftype Num i lt-
1 loop exitif(i gt MAX) datai lt- i i lt- i
1 endloop
data
1 2 3 4 5 6 7 8 9
10
10
i
173
MAX is 10 Vec_max definesa Array1..MAX of
Num data isoftype Vec_max i isoftype Num i lt-
1 loop exitif(i gt MAX) datai lt- i i lt- i
1 endloop
data
1 2 3 4 5 6 7 8 9
10
10
i
174
MAX is 10 Vec_max definesa Array1..MAX of
Num data isoftype Vec_max i isoftype Num i lt-
1 loop exitif(i gt MAX) datai lt- i i lt- i
1 endloop
data
1 2 3 4 5 6 7 8 9
10
10
i
175
MAX is 10 Vec_max definesa Array1..MAX of
Num data isoftype Vec_max i isoftype Num i lt-
1 loop exitif(i gt MAX) datai lt- i i lt- i
1 endloop
data
1 2 3 4 5 6 7 8 9
10
11
i
176
MAX is 10 Vec_max definesa Array1..MAX of
Num data isoftype Vec_max i isoftype Num i lt-
1 loop exitif(i gt MAX) datai lt- i i lt- i
1 endloop
data
1 2 3 4 5 6 7 8 9
10
11
i
177
MAX is 10 Vec_max definesa Array1..MAX of
Num data isoftype Vec_max i isoftype Num i lt-
1 loop exitif(i gt MAX) datai lt- i i lt- i
1 endloop
data
1 2 3 4 5 6 7 8 9
10
11
i
178
MAX is 10 Vec_max definesa Array1..MAX of
Num data isoftype Vec_max i isoftype Num i lt-
1 loop exitif(i gt MAX) datai lt- i i lt- i
1 endloop
data
1 2 3 4 5 6 7 8 9
10
11
i
179
MAX is 10 Vec_max definesa Array1..MAX of
Num data isoftype Vec_max i isoftype Num i lt-
1 loop exitif(i gt MAX) datai lt- i i lt- i
1 endloop
data
1 2 3 4 5 6 7 8 9
10
11
i
180
A More Complex Problem
  • Write a module which returns an array with the
    following characteristics
  • Every odd element has the first half of the
    alphabet in ascending order every even element
    has the second half of the alphabet in descending
    order.

A1 A A2 Z A3 B A4 Y A5
C A6 X . . . A23 L A24
O A25 M A26 N
181
A
A
Z
B
Y
C
L
O
M
N
Every odd element has the first half of the
alphabet in ascending order every even element
has the second half of the alphabet in descending
order.
182
A First Try
  • ALPHAS is 26
  • A isoftype CharArrayType
  • i isoftype Num
  • up isoftype char
  • i lt- 1
  • up lt- A
  • loop
  • exitif( i gt ALPHAS )
  • Ai lt- up
  • up lt- next_character(up)
  • i lt- i 2
  • endloop

183
A
A
B
C
L
M
Every odd element has the first half of the
alphabet in ascending order every even element
has the second half of the alphabet in descending
order.
184
  • ALPHAS is 26
  • A isoftype Array_Type
  • i isoftype Num
  • up, down isoftype char
  • i lt- 1
  • up lt- A
  • down lt- Z
  • loop
  • exitif( i gt ALPHAS )
  • Ai lt- up
  • Ai 1 lt- down
  • up lt- next_character(up)
  • down lt- previous_character(down)
  • i lt- i 2
  • endloop

185
A
A
Z
B
Y
C
L
O
M
N
Every odd element has the first half of the
alphabet in ascending order every even element
has the second half of the alphabet in descending
order.
186
A 2-D Iterative Traversal Example
  • We have a 2-D array
  • We want to traverse the array and set each
    element to the product of its row position and
    column position
  • (i.e. the element at position i,j should
    contain the value ij)

1
2
3
4
2
i
4
6
8
3
6
9
12
j
187
MAX_COLS is 4 Row_Type definesa
Array1..MAX_COLS of Num Sample isoftype
Row_type
Sample
1 2 3 4
188
MAX_ROWS is 3 MAX_COLS is 4 Row_Type definesa
Array1..MAX_COLS of Num Matrix definesa
Array1..MAX_ROWS of Row_Type Data isoftype
Matrix
1 2 3
1 2 3 4
189
MAX_ROWS is 3 MAX_COLS is 4 Row_Type definesa
Array1..MAX_COLS of Num Matrix definesa
Array1..MAX_ROWS of Row_Type Data isoftype
Matrix Row, Col isoftype Num Row lt- 1 loop
exitif(Row gt MAX_ROWS) Col lt- 1 loop
exitif(Col gt MAX_COLS) DataRowCol lt- Row
Col Col lt- Col 1 endloop Row lt- Row
1 endloop
190
MAX_ROWS is 3 MAX_COLS is 4 Row_Type definesa
Array1..MAX_COLS of Num Matrix definesa
Array1..MAX_ROWS of Row_Type Data isoftype
Matrix Row, Col isoftype Num
1 2 3
1 2 3 4
191
Row lt- 1 loop exitif(Row gt MAX_ROWS) Col lt-
1 loop exitif(Col gt MAX_COLS)
DataRowCol lt- Row Col Col lt- Col 1
endloop Row lt- Row 1 endloop
MAX_ROWS is 3 MAX_COLS is 4
1 2 3
1 2 3 4
192
Row lt- 1 loop exitif(Row gt MAX_ROWS) Col lt-
1 loop exitif(Col gt MAX_COLS)
DataRowCol lt- Row Col Col lt- Col 1
endloop Row lt- Row 1 endloop
MAX_ROWS is 3 MAX_COLS is 4
1 2 3
1 2 3 4
193
Row lt- 1 loop exitif(Row gt MAX_ROWS) Col lt-
1 loop exitif(Col gt MAX_COLS)
DataRowCol lt- Row Col Col lt- Col 1
endloop Row lt- Row 1 endloop
MAX_ROWS is 3 MAX_COLS is 4
1 2 3
1 2 3 4
194
Row lt- 1 loop exitif(Row gt MAX_ROWS) Col lt-
1 loop exitif(Col gt MAX_COLS)
DataRowCol lt- Row Col Col lt- Col 1
endloop Row lt- Row 1 endloop
MAX_ROWS is 3 MAX_COLS is 4
1 2 3
1 2 3 4
195
Row lt- 1 loop exitif(Row gt MAX_ROWS) Col lt-
1 loop exitif(Col gt MAX_COLS)
DataRowCol lt- Row Col Col lt- Col 1
endloop Row lt- Row 1 endloop
MAX_ROWS is 3 MAX_COLS is 4
1 2 3
1 2 3 4
196
Row lt- 1 loop exitif(Row gt MAX_ROWS) Col lt-
1 loop exitif(Col gt MAX_COLS)
DataRowCol lt- Row Col Col lt- Col 1
endloop Row lt- Row 1 endloop
MAX_ROWS is 3 MAX_COLS is 4
1 2 3
1 2 3 4
197
Row lt- 1 loop exitif(Row gt MAX_ROWS) Col lt-
1 loop exitif(Col gt MAX_COLS)
DataRowCol lt- Row Col Col lt- Col 1
endloop Row lt- Row 1 endloop
MAX_ROWS is 3 MAX_COLS is 4
1 2 3
1 2 3 4
198
Row lt- 1 loop exitif(Row gt MAX_ROWS) Col lt-
1 loop exitif(Col gt MAX_COLS)
DataRowCol lt- Row Col Col lt- Col 1
endloop Row lt- Row 1 endloop
MAX_ROWS is 3 MAX_COLS is 4
1 2 3
1 2 3 4
199
Row lt- 1 loop exitif(Row gt MAX_ROWS) Col lt-
1 loop exitif(Col gt MAX_COLS)
DataRowCol lt- Row Col Col lt- Col 1
endloop Row lt- Row 1 endloop
MAX_ROWS is 3 MAX_COLS is 4
1 2 3
1 2 3 4
200
Row lt- 1 loop exitif(Row gt MAX_ROWS) Col lt-
1 loop exitif(Col gt MAX_COLS)
DataRowCol lt- Row Col Col lt- Col 1
endloop Row lt- Row 1 endloop
MAX_ROWS is 3 MAX_COLS is 4
1 2 3
1 2 3 4
201
Row lt- 1 loop exitif(Row gt MAX_ROWS) Col lt-
1 loop exitif(Col gt MAX_COLS)
DataRowCol lt- Row Col Col lt- Col 1
endloop Row lt- Row 1 endloop
MAX_ROWS is 3 MAX_COLS is 4
1 2 3
1 2 3 4
202
Row lt- 1 loop exitif(Row gt MAX_ROWS) Col lt-
1 loop exitif(Col gt MAX_COLS)
DataRowCol lt- Row Col Col lt- Col 1
endloop Row lt- Row 1 endloop
MAX_ROWS is 3 MAX_COLS is 4
1 2 3
1 2 3 4
203
Row lt- 1 loop exitif(Row gt MAX_ROWS) Col lt-
1 loop exitif(Col gt MAX_COLS)
DataRowCol lt- Row Col Col lt- Col 1
endloop Row lt- Row 1 endloop
MAX_ROWS is 3 MAX_COLS is 4
1 2 3
1 2 3 4
204
Row lt- 1 loop exitif(Row gt MAX_ROWS) Col lt-
1 loop exitif(Col gt MAX_COLS)
DataRowCol lt- Row Col Col lt- Col 1
endloop Row lt- Row 1 endloop
MAX_ROWS is 3 MAX_COLS is 4
1 2 3
1 2 3 4
205
Row lt- 1 loop exitif(Row gt MAX_ROWS) Col lt-
1 loop exitif(Col gt MAX_COLS)
DataRowCol lt- Row Col Col lt- Col 1
endloop Row lt- Row 1 endloop
MAX_ROWS is 3 MAX_COLS is 4
1 2 3
1 2 3 4
206
Row lt- 1 loop exitif(Row gt MAX_ROWS) Col lt-
1 loop exitif(Col gt MAX_COLS)
DataRowCol lt- Row Col Col lt- Col 1
endloop Row lt- Row 1 endloop
MAX_ROWS is 3 MAX_COLS is 4
1 2 3
1 2 3 4
207
Row lt- 1 loop exitif(Row gt MAX_ROWS) Col lt-
1 loop exitif(Col gt MAX_COLS)
DataRowCol lt- Row Col Col l
Write a Comment
User Comments (0)
About PowerShow.com