快速排序,冒泡排序,插入排序 完整示例
来源:互联网 发布:《人工智能》书籍 编辑:程序博客网 时间:2024/06/07 17:25
快速排序
using System;using System.Collections.Generic;using System.Collections;
using System.Text;
namespace ConsoleApplication12{ class Program { static void Main(string[] args) { ArrayList at = new ArrayList(); int[] number = new int[] { 5679, 4, 36, 67976, 124, 235, 453, 436, 6589, 0, 5, 6, 346, 457, 34, 3642 }; foreach (int i in number) { at.Add(i); } ArrayList al = QuickSort(at); foreach (int j in al) { Console.WriteLine(j); } Console.ReadKey(); } static ArrayList QuickSort(ArrayList arrayList) { if (arrayList.Count <= 1) return arrayList; int pivotIndex = arrayList.Count / 2; int pivot = (int)arrayList[pivotIndex]; arrayList.Remove(pivot); ArrayList left = new ArrayList(); ArrayList right = new ArrayList(); for (int i = 0; i < arrayList.Count; i++) { // 改变排序方式, 只要改变这里的比较方式 if ((int)arrayList[i] < pivot) { left.Add(arrayList[i]); } else { right.Add(arrayList[i]); } } ArrayList newArrayList = QuickSort(left); newArrayList.Add(pivot); newArrayList.AddRange(QuickSort(right)); return newArrayList; }
}}
冒泡排序
using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
namespace ConsoleApplication12
{
class Program
{
static void Main(string[] args)
{
int[] number=new int[]{5679,4,36,67976,124,235,453,436,6589,0,5,6,346,457,34,3642};
QuickSort(ref number);
foreach (int j in number)
{
Console.WriteLine(j);
}
Console.ReadKey();
}
static void QuickSort(ref int[] number)
{
for (int i = 0; i < number.Length; i++)
{
// 改变排序方式, 只要改变这里的比较方式
for (int j = 0; j < number.Length - i-1; j++)
{
if (number[j]>number[j+1])
{
int temp = number[j];
number[j] = number[j + 1];
number[j + 1] = temp;
}
}
}
}
}
}
插入排序
using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
namespace ConsoleApplication12
{
class Program
{
static void Main(string[] args)
{
int[] number=new int[]{5679,4,36,67976,124,235,453,436,6589,0,5,6,346,457,34,3642};
QuickSort(ref number);
foreach (int j in number)
{
Console.WriteLine(j);
}
Console.ReadKey();
}
static void QuickSort(ref int[] number)
{
for (int i = 1; i < number.Length; i++)
{
int temp = number[i];
int j=i;
while (j>0 &&number[j-1]>temp)
{
number[j] = number[j-1];
--j;
}
number[j] = temp;
}
}
}
}
- 快速排序,冒泡排序,插入排序 完整示例
- 冒泡排序、快速排序示例
- 选择排序、冒泡排序、插入排序、基数排序、快速排序、归并排序完整C++实现
- 快速排序和冒泡排序,插入排序
- 冒泡排序、插入排序及快速排序
- 冒泡排序、快速排序和插入排序
- Scala冒泡排序、快速排序、插入排序
- 冒泡排序快速排序插入排序
- 冒泡排序 快速排序 插入排序 堆排序 选择排序
- 插入排序、选择排序、冒泡排序、快速排序、堆排序
- 数组排序:快速排序,选择排序,冒泡排序,插入排序
- Java 排序 快速排序 冒泡排序 选择排序 插入排序
- Java-冒泡排序、快速排序、插入排序、快速排序
- 冒泡、插入、选择、快速排序
- 冒泡+直接插入+ 快速排序
- 冒泡,快速,选择,插入排序
- 排序------快速,插入,选择,冒泡
- 插入排序 冒泡 选择 快速
- 【转】makefile 获取指定目录下源文件名称
- 持续集成(1)--配置maven使用nexus
- 我是残疾人--我近视
- 面试题——跑马灯
- 软件工程师与商人的区别
- 快速排序,冒泡排序,插入排序 完整示例
- android--Spinner(菜单下拉控件)
- ldr与adr的区别
- CAS-Client客户端研究(五)-SingleSignOutFilter
- url编码混乱下下载工具如何应对
- C++程序运行时内存布局之----------this到底是什么?
- 图片管理
- 修改Tomcat内存大小(java.lang.OutOfMemoryError: Java heap space)
- navicat9.0 激活码