零起点学算法85——数组算法中插入一个数

零起点学算法_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
评价文档:
4页免费5页免费1页免费1页免费1页免费6页免费2页免费36页2下载券2页免费21页2下载券
喜欢此文档的还喜欢59页免费62页7下载券15页1下载券186页1下载券126页免费
零起点学算法|
把文档贴到Blog、BBS或个人站等:
普通尺寸(450*500pix)
较大尺寸(630*500pix)
你可能喜欢创建控制台
using System.Collections.G
using System.L
using System.T
namespace Consolepaixu
class Program
private const int Num = 30;
private const int MaxValue = 30;
private const int MinValue = 1;
static void Main(string[] args)
int[] a = GenerateNumber3();
int[] b = BubbleSort(a);
for (int i = 0; i & b.L i++)
Console.Write(b[i].ToString() + & &);
Console.ReadLine();
public static int[] BubbleSort(int[] list)
for (int j = 0; j & list.L j++)
for (i = list.Length - 1; i & i--)
if (list[j] & list[i])
temp = list[j];
list[j] = list[i];
public static
int[] GenerateNumber3()
//用于存放1到30这30个数
int[] container = new int[30];
//用于保存返回结果
int[] result = new int[30];
Random random = new Random();
for (int i =1; i &= 30; i++)
container[i-1] =
for (int i = 0; i &30; i++)
//从[1,container.Count + 1)中取一个随机值,保证这个值不会超过container的元素个数
index = random.Next(0, container.Length - i-1);
//以随机生成的值作为索引取container中的值
value = container[index];
//将随机取得的值放到结果集合中
result[i] =
//将刚刚使用到的数从容器集合中移到末尾去
container[index] = container[container.Length - i-1];
//将队列对应的值移到队列中
container[container.Length - i-1] =
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:6782次
排名:千里之外
(1)(1)(4)(4)

我要回帖

更多关于 数组排序算法 的文章

 

随机推荐