冒泡排序大比拼---看看谁的算法最简单
2009-12-23 14:13
260 查看
一.
///////////////////////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
int[] a = { 3, 4, 7, 10, 5, 9 };
int[] b = BubbleSort(a);
for (int i = 0; i < b.Length; i++)
{
Console.Write(b[i].ToString() + " ");
}
Console.ReadLine();
}
public static int[] BubbleSort(int[] list)
{
int i, temp;
for (int j = 0; j < list.Length; j++)
{
for (i = list.Length - 1; i > j; i--)
{
if (list[j] < list[i])
{
temp = list[j];
list[j] = list[i];
list[i] = temp;
}
}
}
return list;
}
}
}
二.
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static void Main(string[] args)
{
int[] a = { 3, 4, 7, 10, 5, 9 };
Array.Sort(a);
for (int i = 0; i < b.Length; i++)
{
Console.Write(b[i].ToString() + " ");
}
Console.ReadLine();
}
///////////////////////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
int[] a = { 3, 4, 7, 10, 5, 9 };
int[] b = BubbleSort(a);
for (int i = 0; i < b.Length; i++)
{
Console.Write(b[i].ToString() + " ");
}
Console.ReadLine();
}
public static int[] BubbleSort(int[] list)
{
int i, temp;
for (int j = 0; j < list.Length; j++)
{
for (i = list.Length - 1; i > j; i--)
{
if (list[j] < list[i])
{
temp = list[j];
list[j] = list[i];
list[i] = temp;
}
}
}
return list;
}
}
}
二.
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static void Main(string[] args)
{
int[] a = { 3, 4, 7, 10, 5, 9 };
Array.Sort(a);
for (int i = 0; i < b.Length; i++)
{
Console.Write(b[i].ToString() + " ");
}
Console.ReadLine();
}
相关文章推荐
- java常用算法之冒泡排序简单例子
- 三个简单的算法—冒泡排序
- PHP算法学习之“简单的交换排序”,“冒泡排序”以及“改进后的冒泡排序”
- 简单算法-冒泡排序[php实现]
- js 中的 一些简单算法(二)之 双层循环—冒泡排序
- java简单算法(二分查找 冒泡排序 判断是否为素数)
- php算法最简单的一例---冒泡排序
- 最简单的排序算法之一冒泡排序----js实现
- 简单排序算法--冒泡排序
- 简单算法之冒泡排序
- java数据结构与算法-简单排序-冒泡排序
- js基本算法:冒泡排序,二分查找的简单实例
- 简单排序算法:冒泡排序(交换排序)
- leetcode--Valid Palindrome--- 算法简单,需要看看怎么写的
- 五、排序算法之简单算法——冒泡排序、简单选择排序和直接插入排序
- 简单的拆分字符串和冒泡排序的算法
- C++简单排序算法之冒泡排序
- 简单的算法---冒泡排序
- 最简单的算法-冒泡排序
- 简单算法--冒泡排序、快速排序、选择排序及二分法