Monday, December 30, 2013

Swap using a temporary variable

Swapping means exchanging contents of two memory location or variables. There are various application of swapping in Computers. Swapping is used in variety of Sort algorithms. On a wider perspective swapping is used to provide virtual memory.

Swap using a temporary variable is very simple.
temp=a
a=b
b=temp

Say a=4, b=7
temp=4   [temp=a]
a=7         [a=b]
b=4         [b=temp]
a=7, b=4

Swap using a temporary variable is applicable to any kind of data value.


No comments:

Post a Comment