数据结构和算法 - C#语言描述

 

//平时下班自己学习用的

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.ObjectModel;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Text.RegularExpressions;

namespace DSC1
{
    class Program
    {
        static void Main(string[] args)
        {
            //Name myName = new Name("wang", "wei", "guo");
            //string fullName, inits;
            //fullName = myName.ToString();
            //inits = myName.Initials();
            //Console.WriteLine("My Name is {0}", fullName);
            //Console.WriteLine("Init is {0}", inits);
            //Console.ReadLine();

            //Collection names = new Collection();
            //names.Add("David");
            //names.Add("bernica");

            //foreach(Object name in names)
            //{
            //    Console.WriteLine(name);
            //}

            //Console.WriteLine("Count : " + names.Count());

            //Console.ReadLine();

            //int num1 = 100;
            //int num2 = 200;

            //Swap<int>(ref num1, ref num2);
            //Console.WriteLine(num1);
            //Console.WriteLine(num2);
            //Console.ReadLine();

            //int[] nums = new int[10000];
            //BuildArray(nums);
            //TimeSpan duration;
            //Timing2 time2 = new Timing2();
            //time2.startTime();
            //DisplayNums(nums);
            //DisplayNums(nums);
            //DisplayNums(nums);
            //time2.stopTime();
            //Console.WriteLine(time2.Result().TotalSeconds);
            duration = Process.GetCurrentProcess().TotalProcessorTime;
            Console.WriteLine(duration.TotalSeconds);
            //Console.ReadLine();

            //int[] numbers;
            //numbers = new int[] { 1, 2, 3 };
            //Type arrayType = numbers.GetType();
            //if(arrayType.IsArray)
            //{
            //    Console.WriteLine("This is a Array");
            //}
            //else
            //{
            //    Console.WriteLine("This is not a Array");

            //}
            //Console.ReadLine();

            //int[,] grades = new int[,]
            //{
            //    {1,82,74,89,100},
            //    {2,93,96,85,86}
            //};

            //int last_grade = grades.GetUpperBound(1);
            //double average = 0.0;
            //int total;
            //int last_student = grades.GetUpperBound(0);  //最后一个学生的index
            //for(int row=0;row<=last_student;row++)
            //{
            //    total = 0;
            //    for(int col=1;col<=last_grade;col++)
            //    {
            //        total += grades[row, col];
            //    }
            //    average = total / last_grade;
            //    Console.WriteLine(average);
            //}

            //ArrayList names = new ArrayList();
            //names.Add("Mike");
            //names.Add("Beata");
            //Console.WriteLine("The Original list of names: ");
            //foreach(Object name in names)
            //{
            //    Console.Write(name + " ");
            //}

            //string[] newNames = new string[] { "David", "Michael" };
            //ArrayList moreNames = new ArrayList();
            //moreNames.Add("wwg");

            //names.InsertRange(0, newNames);
            //names.AddRange(moreNames);

            //foreach (Object name in names)
            //{
            //    Console.Write(name + " ");
            //}


            //CArray nums = new CArray(10);
            //Random rnd = new Random(100);

            //for (int i = 0; i < 10;i++ )
            //{
            //    nums.Insert(rnd.Next(0,100));
            //}

            //nums.DisplayElements();

            //nums.SelectionSort();

            //Timing2 sortTime = new Timing2();
            //Random rnd = new Random(10000);
            //int numItems = 10000;
            //CArray theArray = new CArray(numItems);
            //for (int i = 0; i < numItems;i++ )
            //{
            //    theArray.Insert(rnd.Next(0,10000));
            //}

            //sortTime.startTime();
            //theArray.SelectionSort();
            //sortTime.stopTime();
            //Console.WriteLine("SelectionSort : " + sortTime.Result().TotalMilliseconds);
            //theArray.Clear();

            //for (int i = 0; i < numItems; i++)
            //{
            //    theArray.Insert((int)(rnd.NextDouble() * 100));
            //}

            //sortTime.startTime();
            //theArray.BubbleSort();
            //sortTime.stopTime();
            //Console.WriteLine("BubbleSort : " + sortTime.Result().TotalMilliseconds);
            //theArray.Clear();

            //int[] numbers = new int[100];
            //StreamReader numFile = File.OpenText(@"d:/wwgData/numbers.txt");
            //for (int i = 0; i < numbers.Length; i++)
            //{
            //    numbers[i] = Convert.ToInt32(numFile.ReadLine(), 10);
            //}

            //int searchNumber;
            //Console.Write("Enter a number to search for: ");
            //searchNumber = Convert.ToInt32(Console.ReadLine(), 10);

            //bool found;
            //found = SeqSearch(numbers, searchNumber);

            //Random random = new Random();
            //CArray mynums = new CArray(10);
            //for (int i = 0; i <= 9; i++)
            //{
            //    mynums.Insert(random.Next(10));
            //}
            //mynums.BubbleSort();

            //mynums.DisplayElements();
            //int position = mynums.binSearch(7);
            //if (position>-1)
            //{
            //    Console.WriteLine("found it");
            //}
            //else
            //{
            //    Console.WriteLine("not found it");
            //}

            回文
            //CStack alist = new CStack();
            //string ch;
            //string word = "sees";
            //bool ishui = true;
            //for (int x = 0; x < word.Length;x++ )
            //{
            //    alist.push(word.Substring(x, 1));
            //}
            //int pos = 0;
            //while(alist.count>0)
            //{
            //    ch = alist.pop().ToString(); //出栈,是最后一个字母
            //    if(ch != word.Substring(pos,1))
            //    {//不是回文
            //        ishui = false;
            //        break;
            //    }

            //    pos++;
            //}

            //if (ishui)
            //{
            //    Console.WriteLine("is hui");
            //}
            //else
            //{
            //    Console.WriteLine("no hui");

            //}


            //使用Stack完成表达式计算
            //Stack nums = new Stack();
            //Stack ops = new Stack();

            //string expression = "1 + 2 + 3 + 5";
            //Calculate(nums, ops, expression);
            //Console.WriteLine(nums.Pop());

            //int num, baseNum;
            //num = Convert.ToInt32(Console.ReadLine());
            //baseNum = Convert.ToInt32(Console.ReadLine());
            //MulBase(num, baseNum);

            //Queue[] numQueue = new Queue[10];//用于收集用的
            //int[] nums = new int[] { 91, 46, 85, 15, 92, 35, 31, 22 };
            //for (int i = 0; i < 10;i++ )
            //{
            //    numQueue[i] = new Queue();
            //}

            先各位发散
            //RSort(numQueue, nums, DigitType.ones);
            收集
            //BuildArray(numQueue, nums);

            十位发散
            //RSort(numQueue, nums, DigitType.tens);

            收集
            //BuildArray(numQueue, nums);
            //DisplayNums(nums);

            //byte[] ByteSet = new Byte[] { 2};
            //BitArray BitSet = new BitArray(ByteSet);
            //for (int bits = 0; bits <= BitSet.Count - 1; bits++)
            //{
            //    Console.Write(BitSet.Get(bits) + "");
            //}

            //int bits;
            //string[] binNumber = new string[8];
            //byte[] ByteSet = new Byte[] { 5 };
            //BitArray BitSet = new BitArray(ByteSet);
            //bits = 0;

            //int binary = 7;
            //for (int i = 0; i < BitSet.Count - 1;i++ )
            //{
            //    if(BitSet.Get(i)== true)
            //    {
            //        binNumber[binary] = "1";
            //    }
            //    else
            //    {
            //        binNumber[binary] = "0";
            //    }
            //    bits++;
            //    binary--;

            //    if((bits% 8)==0)
            //    {
            //        binary = 7;
            //        bits = 0;
            //        for(int j=0;j<=7;j++)
            //        {
            //            Console.Write(binNumber[j]);
            //        }
            //    }
            //}

            //string string1 = "Hello world";
            //int len = string1.Length;
            //int pos = string1.IndexOf(" ");
            //string firstWord, secondWord;
            //firstWord = string1.Substring(0, pos);
            //secondWord = string1.Substring(pos + 1);
            //Console.Write(firstWord);
            //Console.Write(",");
            //Console.Write(secondWord);

            //string astring = "now is a happy day";
            //ArrayList words = new ArrayList();
            //words = SplitWords(astring);
            //foreach (string word in words)
            //{
            //    Console.Write(word + ",");
            //}

            //string data = "Mike,McMillan,wwg,smm";
            //string[] sdata;
            //char[] delimiter = new char[] { ',' };
            //sdata = data.Split(delimiter, data.Length);
            //foreach(string word in sdata)
            //{
            //    Console.Write(word + " ");
            //}

            //string[] nouns = new string[] { "cat", "dog", "bird", "eggs", "bones" };
            //ArrayList pluralNouns = new ArrayList();
            //foreach(string noun in nouns)
            //{
            //    if(noun.EndsWith("s"))
            //    {

            //    }
            //}

            //string[] words = new string[] { "recieve", "decieve", "reciept" };
            //for (int i = 0; i <= words.GetUpperBound(0);i++ )
            //{
            //    words[i] = words[i].Replace("cie", "cei");
            //    Console.WriteLine(words[i]);
            //}

            //string[,] names = new string[,]
            //{
            //    {"1504","wwg","Ella","steve","Bob"},
            //    {"1133","Elizabeth","Alex","David","Joe"}
            //};

            //for (int outer=0;outer<=names.GetUpperBound(0);outer++)
            //{
            //    for (int inner=0;inner<=names.GetUpperBound(1);inner++)
            //    {
            //        Console.Write(names[outer,inner].PadRight(10)+" ");
            //    }
            //    Console.WriteLine();
            //}

            //string[] names = new string[] { " David", " Raymond", "Mike " };
            //showName(names);

            //StringBuilder stBuff = new StringBuilder("Ken Thompson");
            //Console.WriteLine(stBuff.Length.ToString());
            //Console.WriteLine(stBuff.Capacity.ToString());
            //Console.WriteLine(stBuff.MaxCapacity.ToString());

            //StringBuilder stBuff = new StringBuilder();
            //Console.WriteLine();
            //stBuff.AppendFormat("YOU order is for {0} widges ", 234);
            //Console.WriteLine(stBuff.ToString());

            //StringBuilder stBuff = new StringBuilder("noise in+++++string");
            //stBuff.Remove(9, 5);
            //Console.WriteLine(stBuff);

            //int size = 100000;
            //Timing2 timeSB = new Timing2();
            //Timing2 timeST = new Timing2();
            //for (int i = 0; i <= 0;i++ )
            //{
            //    timeSB.startTime();
            //    BuildSB(size);
            //    timeSB.stopTime();

            //    timeST.startTime();
            //    BuildString(size);
            //    timeST.stopTime();

            //    Console.WriteLine("sb size;" + size + ",time:" + timeSB.Result().TotalMilliseconds);
            //    Console.WriteLine("st size;" + size + ",time:" + timeST.Result().TotalMilliseconds);
            //}


            //string words = "08/14/57 46 02/25/59 45 06/05/85 18 08/14/57 46";
            //string regExp1 = "(?<dates>(//d{2}///d{2}///d{2}))//s(?<ages>(//d{2}))//s";

            //MatchCollection matchSet = Regex.Matches(words, regExp1);
            //int matchPos;
            //if (matchSet.Count > 0)
            //{
            //    foreach (Match aMatch in matchSet)
            //    {
            //        foreach (Capture aCapture in aMatch.Groups["dates"].Captures)
            //        {
            //            Console.WriteLine("date:" + aCapture.ToString());
            //        }
            //        foreach (Capture aCapture2 in aMatch.Groups["ages"].Captures)
            //        {
            //            Console.WriteLine("age:" + aCapture2.ToString());
            //        }

            //    }
            //}

            //string[] words = new string[] { "heal", "heel", "noah", "techno"};
            //string regExp = "h$"; //. 与字符串中任意字符匹配
            //MatchCollection aMatch;

            //foreach (string word in words)
            //{
            //    if (Regex.IsMatch(word, regExp))
            //    {
            //        aMatch = Regex.Matches(word, regExp);
            //        for (int i = 0; i < aMatch.Count; i++)
            //        {
            //            Console.Write(aMatch[i].Value + " ");
            //        }
            //    }

            //}

            //IPAddress myIPs = new IPAddress();
            //myIPs.Add("Mike", "192.111.111.0");
            //myIPs.Add("wwg", "120.0.0.1");
            //Console.WriteLine(myIPs.Count);
            //Console.WriteLine(myIPs.Item("wwg"));
            //myIPs.Clear();
            //Console.WriteLine(myIPs.Count);

            //IPAddress myips = new IPAddress(@"D://data.txt");
            //Console.WriteLine(myips.Count);
            //Console.WriteLine(myips.Item("wwg"));

            //KeyValuePair<string, int>[] gradeBook = new KeyValuePair<string, int>[10];
            //gradeBook[0] = new KeyValuePair<string, int>("McMillan", 99);
            //gradeBook[1] = new KeyValuePair<string, int>("Ruff", 64);

            //for (int i = 0; i <= gradeBook.GetUpperBound(0);i++ )
            //{
            //    Console.WriteLine(gradeBook[i].Key + ":" + gradeBook[i].Value);
            //}

            //string[] names = new string[99];
            //string name;
            //string[] someNames = new string[] { "David", "Jennifer", "Donnie", "Mayno","Raymod","Bernica","Clayton","Beata","Michael","wwg" };
            //int hashVal;
            //for (int i = 0; i < 10;i++ )

            //    name = someNames[i];
            //    hashVal = BetterHash(name, names);
            //    names[hashVal] = name;

            //}

            //ShowDistrib(names);

            //Hashtable symbols = new Hashtable(25);
            //symbols.Add("salary", 100000);
            //symbols.Add("name", "David Durr");
            //symbols.Add("age", 45);
            //symbols.Add("dept", "IT");
            //symbols["sex"] = "Male";
            //Console.WriteLine("The keys are: ");
            //foreach (Object key in symbols.Keys)
            //{
            //    Console.Write(key + ",");
            //}
            //Console.WriteLine();
            //foreach (object key in symbols.Keys)
            //{
            //    Console.WriteLine(key.ToString()+":"+symbols[key].ToString());
            //}

            //LinkList MyList = new LinkList();
            //ListIter iter = new ListIter(MyList);
            //string choice, value;

            //try
            //{
            //    iter.insertAfter("David");
            //    iter.insertAfter("Mike");
            //    iter.InsertBefore("Donnie");

            //    while(true)
            //    {
            //        Console.WriteLine("Enter your choice");
            //        choice = Console.ReadLine().ToLower();

            //        char[] onechar = choice.ToCharArray();

            //        switch (onechar[0])
            //        {
            //            case 'n':
            //                if((!MyList.IsEmpty())&&(!iter.AtEnd()))
            //  

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
数据结构算法C#语言描述》是在.NET框架下用C#语言实现数据结构算法的第一本全面的参考书。《数据结构算法C#语言描述》介绍的方法非常实用,采用了时间测试而非大O表示法来分析算法性能。内容涵盖了数据结构算法的基本原理,涉及数组、广义表、链表、散列表、树、图、排序搜索算法以及更多概率算法和动态规则等高级算法。此外,书中还提供了.NET框架类库中的C#语言实现的数据结构算法。   《数据结构算法C#语言描述》适合作为C#数据结构课程的教材,同时也适合C#专业人士阅读。 随着.NET框架的广泛应用,C#已经成为最受欢迎的程序设计语言之一。但是,市面上尚无用C#语言讲述数据结构算法的图书,广大C#程序员不得不将自 己转换C++或Java描述数据结构,费时费力,而且容易出错。   本书填补了这一空白。而且更加难能可贵的是,作者基于自己多年的教学和实践经验,从开发实战出发,采用了一种与一般数据结构图书不同的讲解方式:充分利 用.NET框架中现成的数据结构类,先讲述各种数据结构怎么在开发中选用,怎样用来解决实际问题,在有了感性认识之后,再深入研究如何实现;同时,用更加 实用的时间测试方法代替常规的大O表示法来分析算法性能,避免了复杂的数学推导。书中除涵盖了数组、广义表、链表、散列表、树、图、排序、搜索等常规数据 结构和算法外,还讨论了概率和动态规划等方面的高级算法。   中文版对原书的代码进行了全面的调试,改正了不少原版存在的问题,保证了代码的质量和技术内容的准确性。   本书是C#程序员不可或缺的实用参考书,也适合作为应用型高校相关专业.NET平台开发课程的教材。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值