(第三季)205-int类型的冒泡排序 206-拓展的通用的冒泡排序方法
来源:互联网 发布:淘宝售后管理软件 编辑:程序博客网 时间:2024/05/16 00:53
/**/using System;namespace CatCry{ class MainClass { // int类型排序 static void Sort(int[] sortArray) { bool swap = false; do { swap = false; for (int i = 0; i < sortArray.Length - 1; i++) { if (sortArray[i] > sortArray[i + 1]) { int temp = sortArray[i]; sortArray[i] = sortArray[i + 1]; sortArray[i + 1] = temp; swap = true; } } } while (swap); } // 泛型方法 static void CommonSort<T>(T[] sortArray, Func<T, T, bool> compareMethod) { bool swap = false; do { swap = false; for (int i = 0; i < sortArray.Length - 1; i++) { if (compareMethod(sortArray[i], sortArray[i + 1])) { T temp = sortArray[i]; sortArray[i] = sortArray[i + 1]; sortArray[i + 1] = temp; swap = true; } } } while (swap); } static void Main() { //int[] sortArray = new int[] {1, 2, 3, 6, 4, 7, 8, 9}; //Sort(sortArray); //foreach (var item in sortArray) //{ // Console.WriteLine(item); //} // Employee[] employees = new Employee[] { new Employee("dsf", 12), new Employee("dsdf", 122), new Employee("dsf", 127), new Employee("dsaf", 127), new Employee("dsvgf", 124), new Employee("dfdsdsf", 143), new Employee("dsaggf", 133), new Employee("dssdfdsf", 132), }; CommonSort<Employee>(employees, Employee.Compare); foreach (var item in employees) { Console.WriteLine(item.ToString()); } // Console.ReadKey(); } }}
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace CatCry{ class Employee { public string Name { get; private set; } public int Salary { get; private set; } public Employee(string name, int salary) { this.Name = name; this.Salary = salary; } // 如果e1 > e2 的话 返回true 否则返回false public static bool Compare(Employee e1, Employee e2) { if (e1.Salary > e2.Salary) { return true; } return false; } public override string ToString() { return Name + ":" + Salary; } }}
0 0
- (第三季)205-int类型的冒泡排序 206-拓展的通用的冒泡排序方法
- int类型的冒泡排序_拓展_
- 通用类型的冒泡排序
- 任意类型通用的qsort冒泡排序
- 使用冒泡法排序int类型的数组
- c++::写一个通用的冒泡排序
- 写一个通用的冒泡排序函数
- 冒泡排序的多种方法
- 冒泡排序的优化方法
- unity->C#->冒泡排序->不用第三个变量的方法
- C 冒泡排序 冒泡排序的优化
- 实现各种类型的冒泡排序
- 冒泡排序的效率
- 简单的冒泡排序
- 冒泡排序的实现
- 单链表的冒泡排序
- 冒泡排序的原理
- C++的冒泡排序
- GO语言初识与编程环境配置
- neutron 更改 dns
- eclipse安装server插件以及dynamic工程所需插件
- 使用ffmpeg快速生成视频截图
- 那些年我们一起清除过的浮动
- (第三季)205-int类型的冒泡排序 206-拓展的通用的冒泡排序方法
- 20160429待整理
- hibernate的抓取和级联操作
- 机器学习之EM算法解析
- 一个字符解决Gradle aar编译参数传递问题是怎样一种体验
- 关于PowerShell中PassThru的实际作用
- tomcat部署solr
- 分布式Unique ID的生成方法一览
- C语言文件读写操作总结