如何使用for循环对数字数组进行排序? [英] how can you sort an array of numbers using for loops?

查看:1062
本文介绍了如何使用for循环对数字数组进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在程序中创建对
排序的函数 使用for循环的任意数量的数组元素,
我需要使用循环,没有排序算法


我需要对数字进行排序的函数,而不是对中位数函数调用sort函数以返回经排序的数组,以便我可以计算中位数

I am trying to create a function in my program that sorts
any number of array elements using for loops,
I need to use for loops and no sort algorithms


i need the function to sort the numbers, than for a median function to call on the sort function to return the sorted array so I can calculate the median

can anybody help me?

推荐答案

我想这是家庭作业:-)

I suppose this is homework :-)

Michael Boothby写道:
michael Boothby wrote:

我需要用于循环并且没有排序算法

I need to use for loops and no sort algorithms



需要某种算法,但必须自己实现,我会做一些研究,因为知道各种可用的算法很方便.气泡排序最简单,但对于大型列表而言则很慢.

就个人而言,对于这样的作业问题,我将创建一个与原始大小相同的目标数组,然后遍历原始对象并插入到目标数组中,以保持目标数组排序.这样,您的源数组将保持原样,这可以在C/C ++中非常快地完成.然后获取中间值.



You need a sort alogorithm, but must implement it yourself, I''d do some research as knowing the various alogrithms available is handy. Bubble sort is easiest but is slow for large lists.

Personally, for a homework question like this, I''d create a destination array the same size as your original, then iterate over the orignal and insert into your destination array keeping the destination array sorted. That way your source array stays in tact, this can be done very quickly in C/C++. Then get the middle value.


michael Boothby写道:
michael Boothby wrote:

我需要用于循环且没有排序算法

I need to use for loops and no sort algorithms


您确实需要一种排序算法(另一方面,for循环是可选的).
正如已经建议的那样,开始阅读有关冒泡排序算法的信息,该算法简单直观,尽管不是性能冠军.
:)


You do need a sort algorithm (on the other hand, for loop is optional).
Start reading, as already suggested, about the bubble-sort algorithm, that is simple and intuitive, albeit not a performance champion.
:)


似乎您正在寻找可以为您做作业的人...每本关于编程基础知识的书中都有关于使用for循环对数字数组进行排序的描述,它''称为气泡排序
It seems that you are looking for someone that do your homeworks for you... Sort arrays of numbers using for loops is lergely described on every book about programming basics, it''s called bubble sort


这篇关于如何使用for循环对数字数组进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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