上一篇 | 下一篇

数据结构与算法(C#实现)系列---演示篇(三)

发布: 2008-6-30 09:32 | 作者: admin | 来源: | 查看: 0次

数据结构与算法(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

字号: | 推荐给好友

21/212>

评分:0

我来说两句

网络推荐