算法练习(5):排序预习(1.1.26)

知识点

  • 排序

题目

1.1.26 将三个数字排序。假设 a、b、c 和 t 都是同一种原始数字类型的变量。证明以下代码能够将 a、 b、c 按照升序排列:
if (a > b) { t = a; a = b; b = t; }
if (a > c) { t = a; a = c; c = t; }
if (b > c) { t = b; b = c; c = t; }


1.1.26 Sorting three numbers. Suppose that the variables a, b, c, and t are all of the same numeric primitive type. Show that the following code puts a, b, and c in ascending order:
if (a > b) { t = a; a = b; b = t; }
if (a > c) { t = a; a = c; c = t; }

top Created with Sketch.