JMU
Swapping
A Programming Pattern (With Examples in Python)


Prof. David Bernstein
James Madison University

Computer Science Department
bernstdh@jmu.edu


Motivation
Review
Review (cont.)
pythonexamples/programmingpatterns/Swapping.py (Fragment: assignment)
        
images/pf_Swapping_Assignment.svg
A Defective Algorithm (cont.)
pythonexamples/programmingpatterns/Swapping.py (Fragment: badswap)
        
images/pf_Swapping_BadSwap.svg
Thinking About the Problem
The Pattern
The Pattern (cont.)
images/Swapping.svg
Example
pythonexamples/programmingpatterns/Swapping.py (Fragment: swordswap)
        
The Example (cont.)
images/pf_Swapping_SwapSteps.svg
A Warning