欢迎来到天天文库
浏览记录
ID:22376336
大小:78.50 KB
页数:10页
时间:2018-10-28
《lzw算法的 c#实现--》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
LZW算法的C#实现>>#undefdebug#definedebugdisplay#undefdebugdictionaryusingSystem;usingSystem.Collections;namespaceLZ{set{_InCharStream=value;}get{return_InCharStream;}}publicArrayListCodingCodeStream{get{return_CodingCodeStream;}}publicArrayListCodingDictionary{get{return_CodingDictionary;}}privatevoidInitCodingDictionary(){_CodingDictionary.Clear(); #ifdebug_CodingDictionary.Add("A");_CodingDictionary.Add("B");_CodingDictionary.Add("C");#elsefor(inti=0;i<256;i++){_CodingDictionary.Add((char)i);}#endif}privatevoidAddCodingDictionary(objectstr){_CodingDictionary.Add(str);}privatevoidAddCodingCodeStream(objectstr){_CodingCodeStream.Add(str);}privateboolISInCodingDictionary(stringPrefix){boolresult=false; intcount=_CodingDictionary.Count;for(inti=0;i<count;i++){stringtemp=_CodingDictionary[i].ToString();if(temp.IndexOf(Prefix)>=0){result=true;break;}}returnresult;}privatestringGetIndexCodingDictionary(stringPrefix){stringresult="0";intcount=_CodingDictionary.Count;for(inti=0;i<count;i++){stringtemp=_CodingDictionary[i].ToString();if(temp.IndexOf(Prefix)>=0){ result=Convert.ToString(i+1);break;}}returnresult;}privatevoidDisplayCodingCodeStream(){System.Console.************");&n123下一页>>>>这篇文章来自..,。bsp;for(inti=0;i<_CodingCodeStream.Count;i++){System.Console.[i].ToString());}}privatevoidDisplayCodingDictionary(){System.Console..Console.(){System.Console.************");System.Console.); }privatevoidInitCodingCodeStream(){_CodingCodeStream.Clear();}privateArrayList_CodingDictionary=ne="";privateArrayList_CodingCodeStream=ne.Length;if(count==0)return;InitCodingDictionary();InitCodingCodeStream();Prefix=_InCharStream[0].ToString();for(inti=1;i<count;i++){c=_InCharStream[i].ToString();if(ISInCodingDictionary(Prefix+c)){Prefix+=c;}else{PrefixIndex=GetIndexCodingDictionary(Prefix);AddCodingCodeStream(PrefixIndex); AddCodingDictionary(Prefix+c);Prefix=c;}}PrefixIndex=GetIndexCodingDictionary(Prefix);AddCodingCodeStream(PrefixIndex);#ifdebugdisplayDisplayInCharStream();DisplayCodingCodeStream();#ifdebugdictionaryDisplayCodingDictionary();#endif#endif}#endregion#regionDecodeprivateArrayList_DeCodeDictionary=ne=ne;publicvoidSetDeCodeSCodetream(int[]obj){intcount=obj.Length; 上一页123下一页>>>>这篇文章来自..,。_DeCodeCodeStream=ne[i]=obj[i];}}publicvoidSetDeCodeSCodetream(ArrayListobj){intcount=obj.Count;_DeCodeCodeStream=ne[i]=System.Convert.ToInt32(obj[i]);}}publicint[]GetDeCodeCodeStream(){return_DeCodeCodeStream;}publicstringOutCharStream{get{stringresult=""; for(inti=0,count=_OutCharStream.Count;i<count;i++){result+=_OutCharStream[i].ToString();}returnresult;}}publicArrayListDeCodeDictionary{get{return_DeCodeDictionary;}}privatevoidInitDeCodeDictionary(){_DeCodeDictionary.Clear();#ifdebug_DeCodeDictionary.Add("A");_DeCodeDictionary.Add("B"); _DeCodeDictionary.Add("C");#elsefor(inti=0;i<256;i++){_DeCodeDictionary.Add((char)i);}#endif}privatevoidInitOutCharStream(){_OutCharStream.Clear();}privatevoidDisplayOutCharStream(){System.Console.************");stringtemp="";for(inti=0;i<_OutCharStream.Count;i++){temp=temp+(_OutCharStream[i].ToString());}System.Console.p); }privatevoidDisplayDeCodeDictionary(){System.Console..Console.WriteLine(_DeCodeDictionary[i].ToString());}}9731248:上一页123>>>>这篇文章来自..,。
此文档下载收益归作者所有
举报原因
联系方式
详细说明
内容无法转码请点击此处