C#排序算法大全(转)
冒泡排序 本人用了C#开发出冒泡排序算法。希望能为C#语言的学习者带来一些益处。不要忘了,学语言要花大力气学数据结构和算法。 using System; namespace BubbleSorter { public class BubbleSorter { public void Sort(int [] list) { int i,j,temp; bool done=false; j=1; while((j<list.Length)&&(!done)) { done=true; for(i=0;i<list.Length-j;i++) { if(list[i]>list[i+1]) { done=false; temp=list[i]; list[i]=list[i+1]; list[i+1]=temp; } } j++; } } } public class MainClass { publ
数据结构与算法(C#实现)系列---演示篇(二)(转)
数据结构与算法(C#实现)系列---演示篇(二) Heavenkiller(原创) public static void ShowGeneralTree_travel() { IEnumerator tmpIEnum; Tree.TraversalType travelType=0; //---------------------提示---------------------------- Console.WriteLine("please choose a the No. of a item you want to travel:"); Console.WriteLine("1.BreadthFirst----- 广度遍历"); Console.WriteLi
数据结构与算法(C#实现)系列---演示篇(三)(转)
数据结构与算法(C#实现)系列---演示篇(三) Heavenkiller(原创) public static void ShowSortedList_Polynomial() { //100+10*x+x^2 + 1+10*x+100x^2 SortedList tmpListA=new SortedList(); SortedList tmpListB=new SortedList(); SortedList tmpListC=new SortedList();//used to store the result SortedList tmpKeyList=new SortedList();//used to store all keys of two polynomials //init polyno
数据结构与算法(C#实现)系列---演示篇(一)(转)
这一篇主要是针对以后各篇的数据类型进行一个实质性的演示。因此希望大家具体看了各种数据结构的分析之后再看这篇。 主要包括如下几个方面的演示:1. 堆栈。 演示了一个利用堆栈作的RPN计算器2. 排序表。演示了一个利用排序表做的多项式表达式的加法运算3. 广义树。演示了深度遍历和广度遍历4. N叉树。演示了N叉树的生成插入删除等基本操作5. 表达式树。演示了一个用二叉树和堆栈做的可以将一个后缀表达式翻译为日常中熟悉的中缀表达式的例子6. AVL树。演示了基本操作 using System;using System.Coll
数据结构与算法(C#实现)系列---AVLTree(二)(转)
数据结构与算法(C#实现)系列---AVLTree(二) //---------------override-------------------- public override void AttachKey(object _obj) { if(!IsEmpty()) throw new Exception("My:this node must be a empty tree node!"); this.key=_obj; //产生一个degree长的数组,并将其初始化为空树 this.treeList=new ArrayList(); this.treeList.Capacity=(int)this.degree; for(int i=0;i<
数据结构与算法(C#实现)系列---AVLTree(一)(转)
数据结构与算法(C#实现)系列---AVLTree(一)using System;using System.Collections;namespace DataStructure{ /// <summary> /// AVLTree 的摘要说明。-----平衡二叉查找树 /// </summary> public class AVLTree:BST { protected int height;//空树的高定义为-1; //构造一棵空的二叉查找树 public AVLTree():base() { // // TODO: 在此处添加构造函数逻辑 // height=-1; } public AVLTree(obje
数据结构与算法(C#实现)系列---N叉树(二)(转)
数据结构与算法(C#实现)系列---N叉树(二) Heavenkiller(原创)public override uint Degree { get { return this.degree; } } //------------------------------------------------------------------------------------- //只用于空树结点 public virtual void AttachKey(object _obj) { if(!IsEmpty())
数据结构与算法(C#实现)系列---二叉树(转)
using System;using System.Collections;namespace DataStructure{ /// <summary> /// BinaryTree 的摘要说明。 /// </summary> public class BinaryTree:NaryTree { //构造二叉空树 public BinaryTree():base(2) { // // TODO: 在此处添加构造函数逻辑 // } public BinaryTree(object _obj):base(2,_obj) {}//------------------------------------------------------------------ protected override
数据结构与算法(C#实现)系列---二叉堆(转)
数据结构与算法(C#实现)系列---二叉堆(数组实现)using System;using System.Collections;namespace DataStructure{ /// <summary> /// BinaryHeap 的摘要说明。-------二叉堆(基于数组的实现) /// </summary> public class BinaryHeap:IPriorityQueue { protected ArrayList array; //建立一个最多容纳_length个对象的空二叉堆 public BinaryHeap(uint _length) { // // TODO: 在此处添加构造函数逻辑 // array
C#冒泡算法(转)
参加多次笔试,居然有几次都考到了冒泡算法,一次是C#版的填空,一次是javascript版的全部写出。 虽然每次都凭着我对冒泡法的理解给弄出来的,但是多多少少与标准模式有点差别,在网上搜了一下关于C#版的冒泡算法,居然也没有一个象样的,自己对照算法模式认真写了一个C#版的,已经测试成功。 同时附上【冒泡排序动画演示】 public void BubbleSort(int[] R) { int i,j,temp; //交换标志 bool exchange; //最多做R.Length-1趟排序 for(i=0; i<R.Length; i++) { //本趟排序开始前,交换标志应为假 exchange=fa
C#算法(四)快速排序(转)
前面我已经推出了三种排序的算法,比较简单。今天我又写了快速排序的算法。希望多多指教。具体的思想,我不做答了。前人的经验。 using System; namespace QuickSorter { public class QuickSorter { private void Swap(ref int l,ref int r) { int s; s=l; l=r; r=s; } public void Sort(int [] list,int low,int high) { int pivot; int l,r; int mid; if(high<=low) return; else if(high==low+1) { if(list[low]>list[high]) Swap(ref list[low],ref list[high]); return;
C#算法(三)希尔排序(转)
朋友们,我最近加紧写C#的一些算法。选择排序,插入算法是我已经推出的。现推出希尔排序.今后,如有时间我将依次推出其它的算法编写。 希尔排序是将组分段,进行插入排序. 对想提高C#语言编程能力的朋友,我们可以互相探讨一下。 如:下面的程序,并没有实现多态,来,帮它实现一下。using System; public class ShellSorter { public void Sort(int [] list) { int inc; for(inc=1;inc<=list.Length/9;inc=3*inc+1); for(;inc>0;inc/=3) { for(int i=inc+1;i<=list.Length;i+=inc) { int t=list[i-1]; in
C#算法(二)插入排序(转)
朋友们,我最近加紧写C#的一些算法。选择排序已经推出的。现推出插入算法。 对想提高C#语言编程能力的朋友,我们可以互相探讨一下。 如:下面的程序,并没有实现多态,来,帮它实现一下。 using System; public class InsertionSorter { public void Sort(int [] list) { for(int i=1;i<list.Length;++i) { int t=list[i]; int j=i; while((j>0)&&(list[j-1]>t)) { list[j]=list[j-1]; --j; } list[j]=t; } } } public class MainClass { public static void Main() { int[
C#算法(一)选择排序(转)
嗨!朋友们,C#将是未来网络开发的首选语言。本人用了C#开发出选择排序算法。希望能为C#语言的学习者带来一些益处。 不要忘了,学语言要花大力气学数据结构和算法。 using System; public class SelectionSorter { // public enum comp {COMP_LESS,COMP_EQUAL,COMP_GRTR}; private int min; // private int m=0; public void Sort(int [] list) { for(int i=0;i<list.Length-1;++i) { min=i; for(int j=i+1;j<list.Length;++j) { if(list[j]<list[min]) min=j; } int t=list[min]; list[mi
Visual C#中的MDI编程(转)
多文档界面就是所谓的MDI,他是从Windows 2.0下的Microsoft Excel电子表格程序开始引入的,这是因为Excel电子表格用户有时需要同时操作多份表格,MDI正好为这种操作多表格提供了很大的方便,于是就产生了MDI程序。在视窗系统3.1版本中,MDI得到了更大范围的应用。其中系统中的程序管理器和文件管理器都是MDI程序。 Visual C#是微软公司推出的下一代主流程序开发语言,他也是一种功能十分强大的程序设计语言,正在受到越来越多的编程人员的喜欢。在Visual C#中,提供了为实现MDI程序设计的很多功能。本文就是通过一个具体的例子来详细的介绍
讲解C#的Namespace(转)
我现在感到学好C#就是就是要知道,C#的基本语法,C#的新的特点,C#能干什么! 其中我感到不管如何,NAMESPACE都是很关键的,可以说不是只对C#而言,而是整个。NET都是由NAMESPACE组成的,所以我在看了C#的基本语法后,就直奔NAMESPACE来了,在这里写下自己的一些感觉,希望能对后面学习的人有所帮助。 NAMESPACE在新的NET环境下编程可以说是无所不在,总之,给我的感觉就是MS的新一代的语言的核心就是NAMESPACE,我们可以通过已经有的NAMESPACE,做我们想做的和愿意做的,当然如果你感觉现有的还不够你的使用的话,你也可以自己来使用现有
C# 语言规范--2.5.7 行指令(转)
行指令可用于改变编译器在输出(如警告和错误)中报告的行号和源文件名称。行指令最通用于从某些其他文本输入生成 C# 源代码的元编程工具。 pp-line:(pp 行:) whitespaceopt # whitespaceopt line whitespace line-indicator pp-new-line(空白可选 # 空白可选 line 空白 行指示符 pp 新行) line-indicator:(行指示符:) decimal-digits whitespace file-name(十进制数字 空白 文件名) decimal-digits(十进制数字) default hiddenfile-name:(文件名:) " file-name-characters &quo
C# 语言规范--2.5.6 区域指令(转)
区域指令用于显式标记源代码的区域。 pp-region:(pp 区域:) pp-start-region conditional-sectionopt pp-end-region(pp 开始区域 条件节可选 pp 结束区域) pp-start-region:(pp 开始区域:) whitespaceopt # whitespaceopt region pp-message(空白可选 # 空白可选 region pp 消息) pp-end-region:(pp 结束区域:) whitespaceopt # whitespaceopt endregion pp-message(空白可选 # 空白可选 endregion pp 消息)区域不具有任何附加的语义含义;区域旨在由程序员或自动工具用来标记源代
C# 语言规范--2.5.5 诊断指令(转)
诊断指令用于显式生成错误信息和警告消息,这些信息的报告方式与其他编译时错误和警告相同。 pp-diagnostic:(pp 诊断:) whitespaceopt # whitespaceopt error pp-message(空白可选 # 空白可选 error pp 消息)whitespaceopt # whitespaceopt warning pp-message(空白可选 # 空白可选 warning pp 消息) pp-message:(pp 消息:) new-line(新行)whitespace input-charactersopt new-line(空白 输入字符可选 新行)示例:#warning Code review needed before check-in#if Debug &&
C# 语言规范--2.5.4 条件编译指令(转)
条件编译指令用于按条件包含或排除源文件中的某些部分。 pp-conditional:(pp 条件:) pp-if-section pp-elif-sectionsopt pp-else-sectionopt pp-endif(pp if 节 pp elif 节可选 pp else 节可选 pp endif) pp-if-section:(pp if 节:) whitespaceopt # whitespaceopt if whitespace pp-expression pp-new-line conditional-sectionopt(空白可选 # 空白可选 if 空白 pp 表达式 pp 新行 条件节可选) pp-elif-sections:(pp elif 节:) pp-elif-section(pp elif 节)pp-elif-sections p