首 页 | 精品电影 | 音乐天堂 | 在线游戏 | Flash MTV | 三湘书屋 | 幽默笑话 | 三湘图库 | 美女写真 | IT知识库 | QQ贴图 | 加入书签

网页制作网络编程图形图象操作系统冲浪宝典软件教学网络安全认证考试通信技术电子商务业内动态书籍教程原码

最近更新 文章分类 多媒体类 精品软件

本站搜索:
您的位置:三湘时空 -> IT知识库 -> 文章分类 -> C#教程 -> 数据结构与算法(C#实现)系列---演示篇(三)  
数据结构与算法(C#实现)系列---演示篇(三)


文章类别:C#教程 来源: 作者: 发表日期:2005-10-4 字体:[ ]

小游戏 | 在线影院 | 幽默笑话 | 源码下载 | Flash MTV | 音乐试听 | 书屋 | 美女写真

                   数据结构与算法(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 polynomial A and show it

              tmpListA.Add(0,100);

              tmpListA.Add(1,10);

              tmpListA.Add(2,1);

              ShowSortedList_ShowPolynomial("tmpListA",tmpListA.GetEnumerator());

 

              //init polynomial B and show it

              tmpListB.Add(0,1);

              tmpListB.Add(1,10);

              tmpListB.Add(2,100);

              ShowSortedList_ShowPolynomial("tmpListB",tmpListB.GetEnumerator());

 

              //init the key list which contains all keys of A and B but everyone once

              IDictionaryEnumerator tmpIDic=tmpListA.GetEnumerator();

              while(tmpIDic.MoveNext()!=false)

              {

                   if(!tmpKeyList.ContainsKey(tmpIDic.Key))

                   {

                       tmpKeyList.Add(tmpIDic.Key,null);

                   }

              }

 

              tmpIDic=tmpListB.GetEnumerator();

              while(tmpIDic.MoveNext()!=false)

              {

                   if(!tmpKeyList.ContainsKey(tmpIDic.Key))

                   {

                       tmpKeyList.Add(tmpIDic.Key,null);

                   }

              }

 

              //Add A and B and show the result

              tmpIDic=tmpKeyList.GetEnumerator();

              while(tmpIDic.MoveNext()!=false)

              {

                   object objA=null,objB=null,objC=null;

                   objC=tmpIDic.Key;

                   if(tmpListA.ContainsKey(objC))

                       objA=tmpListA[objC];

                   if(tmpListA.ContainsKey(objC))

                       objB=tmpListB[objC];

                   //objC=objA+objB;

                   //tmpKeyList[objC]=(int)objA+(int)objC;

                   tmpListC.Add(objC,(int)objA+(int)objB);

 

              }

              ShowSortedList_ShowPolynomial("the addition result of A and B",tmpListC.GetEnumerator());

 

        

             

         }

         public static void ShowSortedList_ShowPolynomial(string tip,IDictionaryEnumerator iDic)

         {

              string strExpress=null;

              iDic.Reset();

              while(iDic.MoveNext()!=false)

              {

                   strExpress+=iDic.Value.ToString()+"*X^"+iDic.Key.ToString()+"+";

              }

              Console.WriteLine(tip+":"+strExpress);

 

         }

 

}

上一篇:数据结构与算法(C#实现)系列---演示篇(二) 下一篇:数据结构与算法(C#实现)系列---树(一)
本栏目热门文章
·C#语言初级入门(1) 2005-10-4
·C# 中的类型转换 2006-4-10
·C#语言初级入门(3) 2005-10-4
·C#语言初级入门(2) 2005-10-4
·C#,深入浅出全接触(一) 2005-10-4
·c#学习笔记(1) 2005-10-4
·C# 3.0语言详解之基本的语言增强 2005-10-22
·C#的前途如何? 2005-10-4
·C#,深入浅出全接触(二) 2005-10-4
·基于C#的接口基础教程之一 2005-10-4
新近更新文章
·C# 3.0新特性初步研究 Part1:使用隐含类型的本地变量 2006-6-12
·C# 4.0语言将出现重大改变,带来一段Code Preview 2006-6-12
·C# 3.0新特性初步研究 Part6:使用查询表达式 2006-6-12
·C# 3.0新特性初步研究 Part5:匿名类型 2006-6-12
·C# 3.0新特性初步研究 Part4:使用集合类型初始化器 2006-6-12
·C# 3.0新特性初步研究 Part3:使用拉姆达表达式 2006-6-12
·C# 3.0新特性初步研究 Part2:使用扩展方法 2006-6-12
·c#泛型学习(二) 2006-5-12
·c#2.0泛型学习(一) 2006-5-12
·C# 编码规范和编程好习惯 2006-4-30
首 页 | 软件发布 | 广告联系 | 下载帮助 | 意见反馈 | 网站地图
  CopyRight? 2002-2004 WWW.SXSKY.NET? All Rights Reserved
三湘时空 站长QQ:82675303 Email: