java - Sort 4 numbers without array -


I have a practice where I will put 4 numbers in ascending order and then without using the array must descend>. I can only use the loop and if the statement I have done it with 3 numbers, but now with 4 numbers I am unable to think about logic.

  Float is great = 1, great 2 = 0, great 3 = 0, great 4 = 0; Int a = 7, b = 5, c = 6, d = 0; // descending (a & gt; b & amp; amp; amp; nbsp; c) {great1 = a; Great 2 = b; Great 3 = C; } And if (a & gt; b & amp; b> c) {great1 = a; Great 2 = c; Great 3 = B; } And if (B & G; A and A and A> C) {great 1 = B; Great 2 = A; Great 3 = C; } And if (B & G; A & A & A & l; c) {great 1 = B; Great 2 = c; Great 3 = A; } And if (C and G; A and A & gt; B) {great 1 = C; Great 2 = A; Great 3 = B; } And {great 1 = C; Great 2 = b; Great 3 = A; }  

One Usage:

  int tmp ; If (a & gt; b) {tmp = a; A = B; B = TMP; } If (C & gt; d) {tmp = c; C = D; D = TMP; } If (A> C) {tmp = a; A = C; C = TMP; } If (b> d) {tmp = b; B = D; D = TMP; } If (b> c) {tmp = b; B = C; C = TMP; }  

You can use to create the optimal sorting network for a low number of input.


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -