与只有3个单元排序int数组 [英] sorting int array with only 3 elements

查看:130
本文介绍了与只有3个单元排序int数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的数组:

int [] myarray =  {17, 6, 8};

什么是这个数组排序的最佳方式,在伪code?

What is the optimal way to sort this array, in pseudocode?

谢谢!

推荐答案

我想这应该是相当快(升序):

I think this should be quite fast (ascending order):

if (el1 > el2) Swap(el1,el2)
if (el2 > el3) Swap(el2,el3)
if (el1 > el2) Swap(el1,el2)

这篇关于与只有3个单元排序int数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆