赞
踩
/*****************************************************************************
创建时间 : 2006年12月19日
文件名 : List_.cs
作者 : 李锋
Email : ruizhilf@139.com
联系电话 : 13828778863,25722732
----------------------最后一次修改时间:2020年05月09日
*******************************************************************************/
using System;
using System.Collections.Generic;
using System.Collections;
using System.Text.RegularExpressions;
using System.IO;
using System.Diagnostics;
using CSharpPlatform;
namespace lf
{
#region DListNote_(双向链表的节点)
/// <summary>
/// 双向链表的节点
/// </summary>
/// <typeparam name="T"></typeparam>
public class DListNote_<T>
{
/// <summary>
/// 节点数据
/// </summary>
public T Data;
/// <summary>
/// 前一个节点
/// </summary>
public DListNote_<T> Prev;
/// <summary>
/// 下一个节点
/// </summary>
public DListNote_<T> Next;
public DListNote_(T aData)
{
Data = aData;
Prev = null;
Next = null;
}
}
#endregion
#region Sortord_( 排序方式)
/// <summary>
/// 排序顺序
/// </summary>
public enum Sortord_
{
s_min_max, //从小到大
s_max_min, //从大到小
s_null //无排序顺序
}
#endregion
#region //====================================================== DList_(双向链表)
/// <summary>
/// 双向链表
/// </summary>
/// <typeparam name="T"></typeparam>
public class DList_<T> : IEnumerable
{
protected DListNote_<T> _First; //第一个节点
protected DListNote_<T> _Last; //最后一个节点
protected int _Count; //节点个数
protected Sortord_ _sortord; //排序顺序
//------------------------------------------------------------------------------------------属性
/// <summary>
/// 实际包含的元素数
/// </summary>
public int Count
{
get
{
return _Count;
}
}
/// <summary>
/// 获取或设置指定索引处的元素
/// </summary>
/// <param name="index">要获得或设置的元素从零开始的索引</param>
/// <returns>指定索引处的元素</returns>
public virtual T this[int index]
{
get
{
return IndexOfNote(index).Data;
}
set
{
IndexOfNote(index).Data = value;
}
}
//---------------------------------------------------------------------------------构造与析构
//---------------------------------------------------------------------------------运算符重载
/// <summary>
///
/// </summary>
/// <param name="dLeft"></param>
/// <param name="dlRight"></param>
/// <returns></returns>
/// 创建时间: 2021-11-07 最后一次修改时间:2021-11-07
public static DList_<T> operator +(DList_<T> dLeft, DList_<T> dlRight)
{
/*
DList_<T> dlResult = new DList_<T> ();
dlResult.Add(dLeft);
dlResult.Add(dlRight);
return dlResult;
*/
return new DList_<T> { dLeft, dlRight };
}
//---------------------------------------------------------------------------------功能函数
/// <summary>
/// 将指定集合的元素添加到末尾
/// </summary>
/// <param name="item">要添加到的末尾处的对象。对于引用类型,该值可以为 null</param>
/// <returns>如成功,返回真,否则返回假</returns>
public virtual void Add(T item)
{
if (_Count == 0)
{
_First = new DListNote_<T>(item);
_First.Next = null;
_First.Prev = null;
_Last = _First;
}
else
{
DListNote_<T> pNew = new DListNote_<T>(item);
pNew.Next = null;
pNew.Prev = _Last;
_Last.Next = pNew;
_Last = pNew;
}
++_Count;
_sortord = Sortord_.s_null; //要重新排序
}
/// <summary>
///
/// </summary>
/// <param name="nIndex"></param>
/// <param name="item"></param>
/// <returns></returns>
/// 创建时间: 2022-08-11 最后一次修改时间:2022-08-12
public virtual void Insert(int nIndex, T item)
{
if ((uint)nIndex > (uint)_Count)
{
throw new Exception("DList_.Insert 插入位置错误!");
}
if (nIndex == 0)
{
if(_First != null)
{
DListNote_<T> dnNew = new DListNote_<T>(item);
_First.Prev = dnNew;
dnNew.Next = _First;
_First = dnNew;
++_Count;
_sortord = Sortord_.s_null;
}
else
{
Add(item);
}
}
else if(nIndex == _Count)
{
Add(item);
}
else
{
DListNote_<T> dnNew = new DListNote_<T>(item);
DListNote_<T> dnNext = IndexOfNote(nIndex);
DListNote_<T> dnPrev = dnNext.Prev;
dnNew.Next = dnNext;
dnNew.Prev = dnPrev;
dnNext.Prev = dnNew;
dnPrev.Next = dnNew;
++_Count;
_sortord = Sortord_.s_null;
}
}
public void Add(DList_<T> dList)
{
if (dList == null)
{
throw new System.Exception("DList_<T>.Add中参数dList==null");
}
DListNote_<T> ld = dList._First;
while (ld != null)
{
Add(ld.Data);
ld = ld.Next;
}
}
public override string ToString()
{
string sResult = "";
DListNote_<T> dnNote = _First;
while (dnNote != null)
{
sResult += dnNote.Data.ToString();
sResult += "\n";
dnNote = dnNote.Next;
}
return sResult;
}
/// <summary>
/// 使用指定的比较器在整个已排序的 中搜索元素,并返回该元素从零开始的索引
/// </summary>
/// <param name="item">要定位的对象。对于引用类型,该值可以为 null。</param>
/// <returns>如果找到 item,则为已排序的 的从零开始的索引;否则为-1; </returns>
public int BinarySearch(T item)
{
switch (_sortord)
{
case Sortord_.s_max_min:
{
if (Count == 0)
{
return -1;
}
if (Count == 1)
{
return (_First.Data as IComparable).CompareTo(item) == 0 ? 0 : -1;
}
if (Count == 2)
{
if( (_First.Data as IComparable).CompareTo(item) == 0) return 0;
if ((_First.Next.Data as IComparable).CompareTo(item) == 0) return 1;
return -1;
}
int nPos = (int)Count / 2; //nPos在中间,所以无素一定要大于等于3才行
int nLeft = 0; //左边远素
int nRight = (int)Count - 1; //右边远素
DListNote_<T> ld;
while (nRight >= 0 && nLeft >= 0)
{
ld = IndexOfNote(nPos);
int iCom = (item as IComparable).CompareTo(ld.Data);
if (iCom > 0)
{
if (nRight == nLeft || nPos == nLeft)
{
return -1;
}
nRight = nPos - 1;
}
else if (iCom < 0)
{
if (nRight == nLeft || nPos == nRight)
{
return -1;
}
nLeft = nPos + 1;
}
else
{
return nPos;
}
nPos = nLeft + (nRight - nLeft + 1) / 2;
}
break;
}
case Sortord_.s_min_max:
{
if (Count == 0)
{
return -1;
}
if (Count == 1)
{
return (_First.Data as IComparable).CompareTo(item) == 0 ? 0 : -1;
}
if (Count == 2)
{
if ((_First.Data as IComparable).CompareTo(item) == 0) return 0;
if ((_First.Next.Data as IComparable).CompareTo(item) == 0) return 1;
return -1;
}
int nPos = (int)Count / 2; //nPos在中间,所以无素一定要大于等于3才行
int nLeft = 0; //左边远素
int nRight = (int)Count - 1; //右边远素
DListNote_<T> ld = null;
while (nRight >= 0 && nLeft >= 0)
{
ld = IndexOfNote(nPos);
int iCom = (item as IComparable).CompareTo(ld.Data);
if (iCom < 0)
{
if (nRight == nLeft || nPos == nLeft)
{
return -1;
}
nRight = nPos - 1;
}
else if (iCom > 0)
{
if (nRight == nLeft || nPos == nRight)
{
return -1;
}
nLeft = nPos + 1;
}
else
{
return nPos;
}
nPos = nLeft + (nRight - nLeft + 1) / 2;
}
break;
}
case Sortord_.s_null:
{
DListNote_<T> pNote = _First;
int iCount = 0;
while (pNote != null)
{
if (pNote.Data.Equals(item))
{
return iCount;
}
pNote = pNote.Next;
++iCount;
}
break;
}
default:
{
return -1;
}
}
return -1;
}
/**
* 功能:清空所有元素的所有数据,并清空链表
* 创建时间:????/??/??
* 最后一次修改时间:2022-07-02
*/
public void Clear()
{
_Count = 0;
DListNote_<T> pTemp1 = _First;
while (pTemp1 != null)
{
DListNote_<T> pTemp2 = pTemp1.Next;
pTemp1.Data = default(T);
pTemp1.Next = null;
pTemp1.Prev = null;
pTemp1 = pTemp2;
}
_First = null;
_Last = null;
}
/// <summary>
/// 确定某元素是否在列表中
/// </summary>
/// <param name="item">查找的对象。对于引用类型,该值可以为 null。</param>
/// <returns>如果在列表中找到 item,则为 true,否则为 false。</returns>
public virtual bool Contains(T item)
{
return BinarySearch(item) != -1;
}
/// <summary>
/// 复制一个链表,清除原来链表的数据
/// </summary>
/// <param name="ld"></param>
public void CopyFrom(DList_<T> ld)
{
if (!this.Equals(ld))
{
Clear();
DListNote_<T> ldItem = ld._First;
while (ldItem != null)
{
Add(ldItem.Data);
ldItem = ldItem.Next;
}
}
}
/*
public int IndexOf(T item)
{
return -1;
}
public int IndexOf(T item, int index)
{
return -1;
}
public void Insert(int index, T item)
{
}
public int LastIndexOf(T item)
{
return -1;
}
public int LastIndexOf(T item, int index, int Count)
{
return -1;
}
*/
/// <summary>
/// 移除指定索引处的元素
/// </summary>
/// <param name="iIndex">要移除的元素的从零开始的索引。</param>
/// <returns>成功返回true,否则返回false</returns>
public bool RemoveAt(int iIndex)
{
if (iIndex < 0 || iIndex + 1 > _Count) { return false; }
DListNote_<T> pNode = _First;
int iCount = 0;
while (pNode != null)
{
if (iCount == iIndex)
{
if (pNode == _First)
{
if (_First.Next == null) //只有一个
{
Clear();
return true;
}
else
{
_First = _First.Next;
_First.Prev = null;
--_Count;
return true;
}
}
else if (pNode == _Last)
{
if (_Last.Prev == null)
{
Clear();
return true;
}
else
{
_Last = _Last.Prev;
_Last.Next = null;
--_Count;
return true;
}
}
else
{
pNode.Prev.Next = pNode.Next;
pNode.Next.Prev = pNode.Prev;
pNode = null;
--_Count;
return true;
}
}
pNode = pNode.Next;
++iCount;
}
return false;
}
/// <summary>
/// 反向排列链表
/// </summary>
/// 创建时间: 2022-04-20 最后一次修改时间:2022-04-20
public virtual void Reverse()
{
DListNote_<T> dnTemp = First;
while(dnTemp != null)
{
LMath.Swap(ref dnTemp.Next, ref dnTemp.Prev);
dnTemp = dnTemp.Prev;
}
LMath.Swap(ref _First, ref _Last);
}
/// <summary>
/// 添加一个元素,并把它放在首位,其它元素后移,如棵后面的元素删除,总无素个数不变,如果无素个数为零,则添加一个无素。
/// </summary>
/// <param name="Item"></param>
/// <param name="bRemoveLast"></param>
/// 创建时间: 2022-04-19 最后一次修改时间:2022-04-19
public void StackPush(T Item, bool bRemoveLast = false){
if (_Count == 0){
Add(Item);
}
else if (_Count == 1){
if (bRemoveLast){
_First.Data = Item;
}
else{
//把无素放在最前
DListNote_<T> dnNew = new DListNote_<T>(Item);
_First.Prev = dnNew;
dnNew.Next = _First;
_First = dnNew;
++_Count;
}
}
else{
if (bRemoveLast){
//删除最后一个元素
_Last = _Last.Prev;
_Last.Next = null;
//把无素放在最前
DListNote_<T> dnNew = new DListNote_<T>(Item);
_First.Prev = dnNew;
dnNew.Next = _First;
dnNew.Prev = null;
_First = dnNew;
}
else {
//把无素放在最前
DListNote_<T> dnNew = new DListNote_<T>(Item);
_First.Prev = dnNew;
dnNew.Next = _First;
dnNew.Prev = null;
_First = dnNew;
++_Count;
}
}
}
/// <summary>
/// 删除第一个元素,出栈
/// </summary>
/// 创建时间: 2022-04-19 最后一次修改时间:2022-04-19
public void StackPop(){ RemoveAt(0); }
/// <summary>
/// 转换成数组
/// </summary>
/// <returns></returns>
public T[] ToArray()
{
T[] aResult = new T[Count];
int n = 0;
DListNote_<T> pNoteTemp = _First;
while (pNoteTemp != null)
{
aResult[n++] = pNoteTemp.Data;
pNoteTemp = pNoteTemp.Next;
}
return aResult;
}
/// <summary>
/// 交换两个节点的数据
/// </summary>
/// <param name="nIndex1"></param>
/// <param name="nIndex2"></param>
/// <returns></returns>
protected virtual bool swapNoteData(int iIndex1, int iIndex2)
{
DListNote_<T> pNote1, pNote2;
pNote1 = IndexOfNote(iIndex1);
pNote2 = IndexOfNote(iIndex2);
if (!(pNote1 != null && pNote2 != null))
{
return false;
}
T ptmp = pNote1.Data;
pNote1.Data = pNote2.Data;
pNote2.Data = ptmp;
return true;
}
/// <summary>
/// 选择排序可以说是最简单的一种排序方法:
/// 1.找到数组中最小的那个元素
/// 2.将最小的这个元素和数组中第一个元素交换位置
/// 3.在剩下的元素中找到最小的的元素,与数组第二个元素交换位置
/// 重复以上步骤,即可以得到有序数组。
/// </summary>
public virtual void sort_selection(Sortord_ sortord)
{
if (_Count == 0 || _Count == 1) return;
//is关键字用于检查对象是否与给定类型兼容。注意了,这里is并不是“是”的意思,而是“兼容”。
if (!(_First.Data is IComparable)) // 判断是否具有IComparable接口,以确定是否存在CompareTo()方法
{
throw new Exception("没有IComparable接口");
}
DListNote_<T> min = _First, tmp = _First.Next;
if (sortord == Sortord_.s_min_max)
{
while (min.Next != null)
{
while (tmp != null)
{
if ((tmp.Data as IComparable).CompareTo(min.Data) < 0) //交换位置
{
T pt = tmp.Data;
tmp.Data = min.Data;
min.Data = pt;
}
tmp = tmp.Next;
}
min = min.Next;
tmp = min.Next;
}
}
else
{
while (min.Next != null)
{
while (tmp != null)
{
if ((tmp.Data as IComparable).CompareTo(min.Data) > 0)
{
T pt = tmp.Data;
tmp.Data = min.Data;
min.Data = pt;
}
tmp = tmp.Next;
}
min = min.Next;
tmp = min.Next;
}
}
_sortord = sortord; //已排序
}
/// <summary>
/// 返回索引的节点,从零开始
/// </summary>
/// <param name="nPos"></param>
/// <returns></returns>
public virtual DListNote_<T> IndexOfNote(int iPos)
{
if (iPos >= _Count || iPos < 0) throw new System.Exception("DListNote_<T>.IndexOfNote 错误索引: " + iPos.ToString() + "!");
uint nindex = 0;
if (iPos > _Count / 2)
{
DListNote_<T> pNote = _Last;
while (pNote != null)
{
if (nindex++ == _Count - iPos - 1){ return pNote;}
pNote = pNote.Prev;
}
}
else
{
DListNote_<T> pNote = _First;
while (pNote != null)
{
if (nindex++ == iPos)
{
return pNote;
}
pNote = pNote.Next;
}
}
return null;
}
/// <summary>
/// 在结点pListItem前面插入一个结点,成功,返回新的结点,否则返回0
/// </summary>
/// <param name="pListItem"></param>
/// <param name="pData"></param>
/// <returns></returns>
protected virtual DListNote_<T> InserNoteFront(DListNote_<T> pListItem, T pData)
{
if (pListItem == null)
{
throw new System.Exception("函数提示:pListItem = null");
}
DListNote_<T> pNote = new DListNote_<T>(pData);
//pNote
pNote.Next = pListItem;
pNote.Prev = pListItem.Prev;
//--pListItem->Prev
if (pListItem.Prev != null)
{
pListItem.Prev.Next = pNote;
}
else
{
_First = pNote;
}
//pListItem
pListItem.Prev = pNote;
++_Count;
return pNote;
}
/// <summary>
/// 在结点pListItem后面插入一个结点,成功,返回新的结点,否则返回0;
/// </summary>
/// <param name="pListItem"></param>
/// <param name="pData"></param>
/// <returns></returns>
protected virtual DListNote_<T> InserNoteBack(DListNote_<T> pListItem, T pData)
{
if (pListItem == null) return null;
DListNote_<T> pNote = new DListNote_<T>(pData);
//pNote
pNote.Prev = pListItem;
pNote.Next = pListItem.Next;
//pListItem->Next
if (pListItem.Next != null)
{
pListItem.Next.Prev = pNote;
}
else
{
_Last = pNote;
}
//--pListItem
pListItem.Next = pNote;
++_Count;
return pNote;
}
/// <summary>
/// 找查一个项,而不是节点,返回的这个节点相当于指针。
/// </summary>
/// <param name="pData">项值</param>
/// <returns></returns>
public DListNote_<T> FindNoteItem(T item)
{
switch (_sortord)
{
case Sortord_.s_max_min:
{
if (Count == 0)
{
return null;
}
if (Count == 1)
{
return (_First.Data as IComparable).CompareTo(item) == 0 ? _First : null;
}
if (Count == 2)
{
if ((_First.Data as IComparable).CompareTo(item) == 0) return _First;
if ((_First.Next.Data as IComparable).CompareTo(item) == 0) return _First.Next;
return null;
}
int nPos = (int)Count / 2; //nPos在中间,所以无素一定要大于等于3才行
int nLeft = 0; //左边远素
int nRight = (int)Count - 1; //右边远素
DListNote_<T> ld = null;
while (nRight >= 0 && nLeft >= 0)
{
ld = IndexOfNote(nPos);
int iCom = (item as IComparable).CompareTo(ld.Data);
if (iCom > 0)
{
if (nRight == nLeft || nPos == nLeft)
{
return null;
}
nRight = nPos - 1;
}
else if (iCom < 0)
{
if (nRight == nLeft || nPos == nRight)
{
return null;
}
nLeft = nPos + 1;
}
else
{
return ld;
}
nPos = nLeft + (nRight - nLeft + 1) / 2;
}
break;
}
case Sortord_.s_min_max:
{
if (Count == 0)
{
return null;
}
if (Count == 1)
{
return (_First.Data as IComparable).CompareTo(item) == 0 ? _First : null;
}
if (Count == 2)
{
if ((_First.Data as IComparable).CompareTo(item) == 0) return _First;
if ((_First.Next.Data as IComparable).CompareTo(item) == 0) return _First.Next;
return null;
}
int nPos = (int)Count / 2; //nPos在中间,所以无素一定要大于等于3才行
int nLeft = 0; //左边远素
int nRight = (int)Count - 1; //右边远素
DListNote_<T> ld = null;
while (nRight >= 0 && nLeft >= 0)
{
ld = IndexOfNote(nPos);
int iCom = (item as IComparable).CompareTo(ld.Data);
if (iCom < 0)
{
if (nRight == nLeft || nPos == nLeft)
{
return null;
}
nRight = nPos - 1;
}
else if (iCom > 0)
{
if (nRight == nLeft || nPos == nRight)
{
return null;
}
nLeft = nPos + 1;
}
else
{
return ld;
}
nPos = nLeft + (nRight - nLeft + 1) / 2;
}
break;
}
case Sortord_.s_null:
{
DListNote_<T> pNote = _First;
while (pNote != null)
{
//总结:Equals比较的永远是变量的内容是否相同,而= =比较的则是引用地址是否相同(前提:此种类型内部没有对Equals 或= = 进行重写操作,
//否则输出可能会有不同)。string 类型是个特例,因为他的内部对这两个都进行了重写。
if ((item as IComparable).CompareTo(pNote.Data) == 0)
{
return pNote;
}
/*
if (pNote.Data.Equals(item))
{
return pNote;
}
*/
pNote = pNote.Next;
}
break;
}
default:
{
return null;
}
}
return null;
}
/// <summary>
/// 把索引为nIndex的节点移到最后
/// </summary>
/// <param name="nIndex"></param>
/// <returns></returns>
protected virtual bool MoveLast(int iIndex)
{
DListNote_<T> pNote = IndexOfNote(iIndex);
if (pNote != null)
{
if (pNote == _Last)
return true;
if (pNote == _First) //此时最少两个节点
{
_First = _First.Next;
_First.Prev = null;
_Last.Next = pNote;
pNote.Prev = _Last;
_Last = pNote;
}
else
{
pNote.Prev.Next = pNote.Next;
pNote.Next.Prev = pNote.Prev;
_Last.Next = pNote;
pNote.Prev = _Last;
_Last = pNote;
}
return true;
}
return false;
}
/// <summary>
///
/// </summary>
/// <param name="dnCurrent"></param>
/// <returns></returns>
/// 创建时间: 2022-02-18 最后一次修改时间:2022-02-18
protected virtual bool MoveLast(DListNote_<T> dnCurrent)
{
if (dnCurrent == null) return false;
_sortord = Sortord_.s_null;
if(_Count == 0)
{
return false;
}
else if(_Count == 1)
{
return true;
}
else if(_Count == 2)
{
if(dnCurrent == _First) //交换_First 与 _Last 数据
{
T tmp = _First.Data;
_First.Data = _Last.Data;
_Last.Data = tmp;
}
return true;
}
else
{
if (dnCurrent == _First)
{
_First = _First.Next;
_First.Prev = null;
_Last.Next = dnCurrent;
dnCurrent.Next = null;
dnCurrent.Prev = _Last;
_Last = dnCurrent;
}
else if (dnCurrent != _Last)
{
dnCurrent.Prev.Next = dnCurrent.Next;
dnCurrent.Next.Prev = dnCurrent.Prev;
_Last.Next = dnCurrent;
dnCurrent.Next = null;
dnCurrent.Prev = _Last;
_Last = dnCurrent;
}
return true;
}
}
/// <summary>
/// 把索引为nIndex的节点移到最前
/// </summary>
/// <param name="nIndex"></param>
/// <returns></returns>
protected virtual bool MoveFirst(int iIndex)
{
DListNote_<T> pNote = IndexOfNote(iIndex);
if (pNote != null)
{
if (pNote == _First)
return true;
if (pNote == _Last) //此时最少两个节点
{
_Last.Prev.Next = null;
_Last = _Last.Prev;
pNote.Prev = null;
pNote.Next = _First;
_First.Prev = pNote;
_First = pNote;
}
else
{
pNote.Prev.Next = pNote.Next;
pNote.Next.Prev = pNote.Prev;
pNote.Next = _First;
_First.Prev = pNote;
pNote.Prev = null;
_First = pNote;
}
return true;
}
return false;
}
/// <summary>
/// 返回第一个节点
/// </summary>
public DListNote_<T> First
{
get
{
return _First;
}
}
/// <summary>
/// 返回最后一个节点
/// </summary>
public DListNote_<T> Last
{
get { return _Last; }
}
//--------------------------------------------------------------------------------------
/// <summary>
/// 构造函数
/// </summary>
public DList_()
{
_Count = 0; _First = null; _Last = null;
_sortord = Sortord_.s_null;
}
/// <summary>
/// 删除链表中的数据
/// </summary>
/// <param name="pData"></param>
/// <returns></returns>
public bool RemoveItem(T pData)
{
if (_sortord == Sortord_.s_null)
{
DListNote_<T> pListItem = _First;
while (pListItem != null)
{
if (pListItem.Data.Equals(pData)) //找到一项
{
if (pListItem == _First) //删除的是第一个节点
{
if (_First.Next != null)
{
_First.Next.Prev = null;
_First = _First.Next;
}
else
{
_First = null;
_Last = null;
}
}
else if (pListItem == _Last) //删除的是最后一个节点
{
if (_Last.Prev != null)
{
_Last.Prev.Next = null;
_Last = _Last.Prev;
}
else
{
_First = null;
_Last = null;
}
}
else //删除的是中间的一个节点
{
pListItem.Next.Prev = pListItem.Prev;
pListItem.Prev.Next = pListItem.Next;
}
--_Count;
return true;
}
pListItem = pListItem.Next;
}
return false;
}
else
{
return RemoveAt(BinarySearch(pData));
}
}
/// <summary>
/// 删除链表中的节点
/// </summary>
/// <param name="pListItem"></param>
/// <returns></returns>
public bool DeleteNode(DListNote_<T> pListItem)
{
if (_Count == 0 || pListItem == null)
{
return false;
}
DListNote_<T> pNote = _First.Next;
while (pNote != null)
{
if (pNote == pListItem) //找到了
{
//pListItem->Prev
if (pListItem.Prev != null)
{
pListItem.Prev.Next = pListItem.Next;
}
else //删除的是第一个节点
{
_First = pListItem.Next;
}
//pListItem->Next
if (pListItem.Next != null)
{
pListItem.Next.Prev = pListItem.Prev;
}
else //删除的是最后一个节点
{
_Last = pListItem.Prev;
}
break;
}
pNote = pNote.Next;
}
if (pNote != null)
{
--_Count;
return true;
}
return false;
}
//--------------------------------------------------------------------------接口
/// <summary>
//示例为了使一个类支持集合初始化器,它必须实现IEnumerable接口并至少具有一个Add方法。从C#6开始,
//IEnumerable可以Add使用扩展方法使用自定义方法扩展任何实现的集合。
/// </summary>
/// 创建时间:2020-05-07 最后一次修改时间: 2020-05-07
/// <returns></returns>
public IEnumerator GetEnumerator()
{
return new DListNoteEnum_<T>(this);
}
}
/// <summary>
/// 节点数据的foreach迭代
/// </summary>
/// 创建时间:2020-05-07 最后一次修改时间: 2020-05-07
/// <typeparam name="T"></typeparam>
public class DListNoteEnum_<T> : IEnumerator
{
private DList_<T> _list;
private int _iIndex;
public DListNoteEnum_(DList_<T> dList)
{
_list = dList;
_iIndex = -1;
}
/// <summary>
/// IEnumerator最终调用的是这个函数访问
/// </summary>
public object Current { get { return _list.IndexOfNote(_iIndex).Data;} }
public bool MoveNext()
{
_iIndex++; //指针首先向前移动一位
return _iIndex < _list.Count;
}
public void Reset()
{
_iIndex = -1;
}
}
#endregion
#region//====================================================== SortList_ 已排序的链表
/// <summary>
/// 已排序的链表
/// </summary>
/// <typeparam name="T"></typeparam>
public class SortList_<T> : DList_<T>
{
public SortList_(Sortord_ sortord)
{
_sortord = sortord;
}
//-------------------------------------------------------------------------------重写
/// <summary>
/// 添加一项到结尾处,item不能为NULL.
/// </summary>
/// <param name="item">项</param>
/// 创建时间: ????-??-?? 最后一次修改时间:2021-11-07
public override void Add(T item)
{
if (item == null)
{
throw new System.Exception("SortList_.Add 方法提示:类型值不能为null!");
}
if ( !(item is IComparable) ) // 判断是否具有IComparable接口,以确定是否存在CompareTo()方法
{
throw new System.Exception("SortList_<" + item.GetType().Name + ">.Add 方法提示:类型“" + item.GetType().Name + "”没有IComparable接口!");
}
if (Count < 3)
{
bool bInsett = false; DListNote_<T> ldNote = First;
while (ldNote != null)
{
if (_sortord == Sortord_.s_max_min)
{
if ((item as IComparable).CompareTo(ldNote.Data) >= 0)
{
base.InserNoteFront(ldNote, item); bInsett = true; break;
}
}
else
{
if ((item as IComparable).CompareTo(ldNote.Data) <= 0)
{
base.InserNoteFront(ldNote, item); bInsett = true; break;
}
}
ldNote = ldNote.Next;
}
if (!bInsett) base.Add(item);
return;
}
int nPos = Count / 2; //nPos在中间,所以无素一定要大于等于3才行
int nLeft = 0; //左边远素
int nRight = Count - 1; //右边远素
if (_sortord == Sortord_.s_max_min)
{
DListNote_<T> ldNote = null;
while (nRight >= 0 && nLeft >= 0)
{
ldNote = IndexOfNote(nPos);
if ((item as IComparable).CompareTo(ldNote.Data) >= 0)
{
if (nRight == nLeft || nPos == nLeft)
{
InserNoteFront(ldNote, item);
return;
}
nRight = nPos - 1;
}
else
{
if (nRight == nLeft || nPos == nRight)
{
InserNoteBack(ldNote, item);
return;
}
nLeft = nPos + 1;
}
nPos = nLeft + (nRight - nLeft + 1) / 2;
}
}
else
{
DListNote_<T> ld = null;
while (nRight >= 0 && nLeft >= 0)
{
ld = IndexOfNote(nPos);
if ((item as IComparable).CompareTo(ld.Data) <= 0)
{
if (nRight == nLeft || nPos == nLeft)
{
InserNoteFront(ld, item);
return;
}
nRight = nPos - 1;
}
else
{
if (nRight == nLeft || nPos == nRight)
{
InserNoteBack(ld, item);
return;
}
nLeft = nPos + 1;
}
nPos = nLeft + (nRight - nLeft + 1) / 2;
}
}
return;
}
}
#endregion
#region//================================================= UniqueList_ 每个项的值都是唯一的链表
/// <summary>
/// 每个项的值都是唯一的链表
/// </summary>
/// <typeparam name="T"></typeparam>
public class UniqueList_<T> : DList_<T>
{
public override void Add(T item)
{
if (BinarySearch(item) == -1)
{
base.Add(item);
}
}
}
#endregion
#region //========================== =========SUList_,已排序,且每一项的值都是唯一的链表
/// <summary>
/// SUList_,已排序,且每一项的值都是唯一的链表
/// </summary>
/// <typeparam name="T"></typeparam>
public class SUList_<T> : SortList_<T>
{
/// <summary>
/// 将指定集合的元素添加到末尾
/// </summary>
/// <param name="item">要添加到的末尾处的对象。对于引用类型,该值可以为 null</param>
/// <returns>如成功,返回真,否则返回假</returns>
public override void Add(T item)
{
if (BinarySearch(item) == -1)
{
base.Add(item);
}
}
public SUList_(Sortord_ sortord)
: base(sortord)
{
}
}
#endregion
#region //=========================================StringList_字符串列表
/// <summary>
/// 字符串列表
/// </summary>
public class StringList_ : DList_<string>
{
/// <summary>
/// 默认构函数
/// </summary>
public StringList_()
{
}
/// <summary>
/// 以分隔符构造一个字符串列表
/// </summary>
/// <param name="sText">原文字符串</param>
/// <param name="sSplit">分隔符</param>
/// <param name="bIgnoreEmptyString">返回列表,空字符串不忽略,如果没有分隔符,则回原字符</param>
/// 创建时间: ????-??-?? 最后一修改时间:2020-05-09,2022-04-20
public StringList_(string sText, string sSplit, bool bIgnoreEmptyString = false)
{
if(sText == null || sText.Length == 0){ return; }
if(sSplit.Length == 0) { Add(sText); return; }
int iStart = 0;
int iIndex = sText.IndexOf(sSplit, iStart);
if (iIndex == -1)
{
Add(sText);
return;
}
while (iIndex != -1 && iStart + 1 <= sText.Length)
{
if (iIndex != iStart)
Add(sText.Substring(iStart, iIndex - iStart));
else //分隔符前面一个字符都没有
{
if (!bIgnoreEmptyString) Add("");
}
iStart = iIndex + sSplit.Length;
iIndex = sText.IndexOf(sSplit, iStart);
if (iIndex == -1)
{
if (sText.Length != iStart)
{
//拷贝最后一个
Add(sText.Substring(iStart, sText.Length - iStart));
}
else // sText.Length == iStart 分隔符在最后,分隔符后面一个字符都没有
{
if (!bIgnoreEmptyString) Add("");
}
}
}
}
#if !WINDOWS_UWP
/// <summary>
/// 把列表写入文件
/// </summary>
/// <param name="sFileName">文件名</param>
public void WriteToFile(string sFileName)
{
System.IO.File.Delete(sFileName);
DListNote_<string> dl = First;
FileStream fs = File.Create(sFileName);
while (dl != null)
{
byte[] bArray = System.Text.Encoding.Default.GetBytes(dl.Data);
fs.Write(bArray, 0, bArray.Length);
bArray = System.Text.Encoding.Default.GetBytes("\r\n");
//fs.WriteByte((byte)'\r'); 不行,UNICODE代码
//fs.WriteByte((byte)'\n');
fs.Write(bArray, 0, bArray.Length);
dl = dl.Next;
}
fs.Close();
}
/// <summary>
/// 从文件中读取列表分隔符为"\r\n";
/// </summary>
/// <param name="sFileName">文件名</param>
/// <returns></returns>
public bool ReadToFile(string sFileName)
{
if (File.Exists(sFileName))
{
FileStream fs = new FileStream(sFileName, FileMode.Open, FileAccess.Read);
Byte[] bArray = new Byte[fs.Length];
fs.Read(bArray, 0, bArray.Length);
fs.Close();
CopyFrom(System.Text.Encoding.Default.GetString(bArray)._Split("\r\n"));
return true;
}
return false;
}
/// <summary>
/// 从文件中读取列表分隔符
/// </summary>
/// <param name="sFileName"></param>
/// <param name="sSplit"></param>
/// <returns></returns>
public bool readToUnicodeFile(string sFileName,string sSplit)
{
if (File.Exists(sFileName))
{
FileStream fs = new FileStream(sFileName, FileMode.Open, FileAccess.Read);
Byte[] bArray = new Byte[fs.Length];
fs.Read(bArray, 0, bArray.Length);
fs.Close();
CopyFrom(System.Text.Encoding.Unicode.GetString(bArray)._Split(sSplit));
return true;
}
return false;
}
public void SaveToUnicodeFile(string sFileName, string sSplit)
{
/*
if(_Count > 0)
{
string sContent = "";
int n = 1;
foreach(string s in this)
{
sContent += s;
if(n != _Count)
sContent += sSplit;
}
Byte[] bArray = System.Text.ASCIIEncoding.ASCII.GetBytes(sContent);
FileStream fs = new FileStream(sFileName, FileMode.Create, FileAccess.Write);
fs.Write(bArray, 0, bArray.Length);
fs.Close();
}
*/
}
/// <summary>
/// 把所有字符串写入磁盘,但每个字符串中的空格和不可打印字符都不会写入,每15个字符串加入一个换行符。
/// </summary>
/// <param name="sFileName"></param>
/// <param name="sSplit"></param>
/// 创建时间: 2022-02-09 最后一次修改时间:2022-02-09
public void WriteToTxtFile(string sFileName, string sSplit)
{
if (_Count > 0)
{
string sContent = "";
int n = 1;
foreach (string s in this)
{
sContent += s._RemoveUnprintableAndWhitespace();
if (n != _Count)
sContent += sSplit;
if(n % 15 == 0)
sContent += "\n";
++n;
}
File.WriteAllText(sFileName,sContent);
}
}
/// <summary>
/// 用分隔 符读取文本文件,空格和不可打印字符都不读取。
/// </summary>
/// <param name="sFileName"></param>
/// <param name="sSplit"></param>
/// 创建时间: 2022-02-09 最后一次修改时间:2022-02-18
public void ReadToTxtFile(string sFileName, string sSplit)
{
if (!File.Exists(sFileName))
return;
string sContent = File.ReadAllText(sFileName)._RemoveUnprintableAndWhitespace();
if(sContent.Trim().Length > 0)
{
CopyFrom(sContent._Split(sSplit));
}
}
#endif
/// <summary>
/// 用分隔符把每个项连成一片,如果分隔符为空,则直接连成一片
/// </summary>
/// <param name="sSeparator">分隔符</param>
/// <returns></returns>
public string ConnectForSeparator(string sSeparator)
{
if (Count == 0) return "";
if (Count == 1) return First.Data;
string tmp = "";
DListNote_<string> ldNote = First;
while (ldNote != Last)
{
tmp += ldNote.Data;
tmp += sSeparator;
ldNote = ldNote.Next;
}
tmp += Last.Data; //加入最后一项
return tmp;
}
/// <summary>
/// 用分隔符把每个项连成一片,如果分隔符为空,则直接连成一片
/// </summary>
/// <param name="cSeparator">分隔符</param>
/// <returns></returns>
public string ConnectForSeparator(char cSeparator)
{
return ConnectForSeparator(cSeparator.ToString());
}
/// <summary>
/// 清空列表,用分隔符把字符串分裂成多项,返回项数
/// </summary>
/// <param name="sText"></param>
/// <param name="sSplit"></param>
/// <returns></returns>
public int splitForSeparator(string sText, char cSplit)
{
Clear();
string[] sl = sText.Split(cSplit);
for (int i = 0; i < sl.Length; ++i)
{
Add(sl[i]);
}
return Count;
}
/// <summary>
/// 查找第一个可印的字符串,如果找到则返回它的值,没找到返回空字符中。
/// </summary>
/// <returns></returns>
/// 创建时间: 2022-01-21 最后一次修改时间:2022-01-21
public string FindFirstPrintableStringValue()
{
DListNote_<string> pNote = _First;
while (pNote != null)
{
if(pNote.Data._IsHavePrintableChar())
{
return pNote.Data;
}
pNote = pNote.Next;
}
return "";
}
/// <summary>
/// 查找第一个可印的字符串的索引,如果找到则返回它的索引,没找到返回-1。
/// </summary>
/// <returns></returns>
/// 创建时间: 2022-01-21 最后一次修改时间:2022-01-21
public int FindFirstPrintableStringIndex()
{
DListNote_<string> pNote = _First;
int nResult = 0;
while (pNote != null)
{
if (pNote.Data._IsHavePrintableChar())
{
return nResult;
}
pNote = pNote.Next;
++nResult;
}
return -1;
}
/// <summary>
///
/// </summary>
/// <param name="ls"></param>
/// <returns></returns>
/// 创建时间: ????-??-?? 最后一次修改时间:2021-10-10
public virtual bool Add(StringList_ ls)
{
DListNote_<string> pNote = ls._First;
while (pNote != null)
{
Add(pNote.Data);
pNote = pNote.Next;
}
return true;
}
/// <summary>
/// 是开头插入一个字符串
/// </summary>
/// <param name="sItem"></param>
/// <returns></returns>
/// 创建时间: 2022-01-18 最后一次修改时间:2022-01-18
public virtual bool InserFront(string sItem)
{
if(_Count == 0)
Add(sItem);
InserNoteFront(_First,sItem);
return true;
}
public int IndexOf(string s)
{
DListNote_<string> pNote = _First;
int iIndex = 0;
while (pNote != null)
{
if (pNote.Data == s)
{
return iIndex;
}
pNote = pNote.Next;
++iIndex;
}
return - 1;
}
}
#endregion
#region //=========================================LSStringList已排序好的字符串列表
/// <summary>
/// 已排序好的字符串列表
/// </summary>
public class SStringList_ : StringList_
{
public SStringList_(Sortord_ sortord)
{
if (sortord == Sortord_.s_null)
{
throw new System.Exception("排序不能为空!");
}
_sortord = sortord;
}
//-------------------------------------------------------------------------------重写
/// <summary>
/// 快速添加字符串,差不多用了8个小时(两天),才写成。
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
public override void Add(string item)
{
if (Count < 3)
{
bool bInsett = false; DListNote_<string> ld = First;
while (ld != null)
{
if (_sortord == Sortord_.s_max_min)
{
if (item.CompareTo(ld.Data) >= 0)
{
base.InserNoteFront(ld, item); bInsett = true; break;
}
}
else
{
if (item.CompareTo(ld.Data) <= 0)
{
base.InserNoteFront(ld, item); bInsett = true; break;
}
}
ld = ld.Next;
}
if (!bInsett) base.Add(item);
return;
}
int nPos = Count / 2; //nPos在中间,所以无素一定要大于等于3才行
int nLeft = 0; //左边远素
int nRight = Count - 1; //右边远素
if (_sortord == Sortord_.s_max_min)
{
DListNote_<string> ld = null;
while (nRight >= 0 && nLeft >= 0)
{
ld = IndexOfNote(nPos);
if (item.CompareTo(ld.Data) >= 0)
{
if (nRight == nLeft || nPos == nLeft)
{
InserNoteFront(ld, item);
return;
}
nRight = nPos - 1;
}
else
{
if (nRight == nLeft || nPos == nRight)
{
InserNoteBack(ld, item);
return;
}
nLeft = nPos + 1;
}
nPos = nLeft + (nRight - nLeft + 1) / 2;
}
}
else
{
DListNote_<string> ld = null;
while (nRight >= 0 && nLeft >= 0)
{
ld = IndexOfNote(nPos);
if (item.CompareTo(ld.Data) <= 0)
{
if (nRight == nLeft || nPos == nLeft)
{
InserNoteFront(ld, item);
return;
}
nRight = nPos - 1;
}
else
{
if (nRight == nLeft || nPos == nRight)
{
InserNoteBack(ld, item);
return;
}
nLeft = nPos + 1;
}
nPos = nLeft + (nRight - nLeft + 1) / 2;
}
}
return;
}
/// <summary>
/// 确定某元素是否在列表中
/// </summary>
/// <param name="item">查找的对象。对于引用类型,该值可以为 null。</param>
/// <returns>如果在列表中找到 item,则为 true,否则为 false。</returns>
public override bool Contains(string item)
{
if (Count == 0) return false;
if (Count == 1) return First.Data.CompareTo(item) == 0;
if (Count == 2) return First.Data.CompareTo(item) == 0 || First.Next.Data.CompareTo(item) == 0;
int nPos = (int)Count / 2; //nPos在中间,所以无素一定要大于等于3才行
int nLeft = 0; //左边远素
int nRight = (int)Count - 1; //右边远素
DListNote_<string> ld = null;
if (_sortord == Sortord_.s_max_min)
{
while (nRight >= 0 && nLeft >= 0)
{
ld = IndexOfNote(nPos);
int iCom = item.CompareTo(ld.Data);
if (iCom > 0)
{
if (nRight == nLeft || nPos == nLeft)
{
return false;
}
nRight = nPos - 1;
}
else if (iCom < 0)
{
if (nRight == nLeft || nPos == nRight)
{
return false;
}
nLeft = nPos + 1;
}
else
{
return true;
}
nPos = nLeft + (nRight - nLeft + 1) / 2;
}
}
else
{
while (nRight >= 0 && nLeft >= 0)
{
ld = IndexOfNote(nPos);
int iCom = item.CompareTo(ld.Data);
if (iCom < 0)
{
if (nRight == nLeft || nPos == nLeft)
{
return false;
}
nRight = nPos - 1;
}
else if (iCom > 0)
{
if (nRight == nLeft || nPos == nRight)
{
return false;
}
nLeft = nPos + 1;
}
else
{
return true;
}
nPos = nLeft + (nRight - nLeft + 1) / 2;
}
}
return false;
}
}
#endregion
#region //=========================================UStringList_值都是唯一的字符串列表,区分大小写
/// <summary>
/// 值都是唯一的字符串列表
/// </summary>
/// <typeparam name="T"></typeparam>
public class UStringList_ : StringList_
{
public override void Add(string item)
{
if(BinarySearch(item) == -1)
base.Add(item);
}
public void Add(string[] sArray)
{
for (int i = 0; i < sArray.Length; ++i)
{
Add(sArray[i]);
}
}
public override bool Add(StringList_ ls)
{
bool bResult = true;
DListNote_<string> pFirst = ls.First;
while (pFirst != null)
{
if (BinarySearch(pFirst.Data) == -1)
{
base.Add(pFirst.Data);
}
else
{
bResult = false;
}
pFirst = pFirst.Next;
}
return bResult;
}
}
#endregion
#region//======================================SUStringList_ 值都是唯一的字符串列表,且已排好序,区分大小写
/// <summary>
/// 值都是唯一的字符串列表,且已排好序,区分大小写
/// </summary>
public class SUStringList_ : SStringList_
{
public override void Add(string item)
{
if (Contains(item))
return;
base.Add(item);
}
public SUStringList_(Sortord_ sortord)
: base(sortord)
{
}
}
#endregion
#region //=========================================UStringListCI_值都是唯一的字符串列表,不区分大小写
/// <summary>
/// 值都是唯一的字符串列表, Case Insensitive(不区分大小写)
/// </summary>
public class UStringListCI_ : StringList_
{
/// <summary>
/// 加入一个串,如果这个串存在,则把这项移到最后。
/// </summary>
/// <param name="item"></param>
/// 创建时间: ????-??-?? 最后一次修改时间:2022-02-18
public override void Add(string item)
{
bool bFind = false;
DListNote_<string> dnTemp = First;
while(dnTemp != null)
{
if(dnTemp.Data.ToLower() == item.ToLower())
{
MoveLast(dnTemp);
bFind = true;
break;
}
dnTemp = dnTemp.Next;
}
if (!bFind)
base.Add(item);
}
/// <summary>
/// 返回前面一个值
/// </summary>
/// <param name="tCurrValue"></param>
/// <returns></returns>
public string GetForward(string sCurr)
{
int iIndex = BinarySearch(sCurr);
if (iIndex != -1)
{
if (iIndex + 1 < Count)
return this[iIndex + 1];
}
return null;
}
/// <summary>
/// 返回后面的一个值
/// </summary>
/// <param name="sCurr"></param>
/// <returns></returns>
public string GetBack(string sCurr)
{
int iIndex = BinarySearch(sCurr);
if (iIndex != -1)
{
if (iIndex - 1 < Count && iIndex - 1 >= 0)
return this[iIndex - 1];
}
return null;
}
}
#endregion
#region //=========================================UStringListCI_值都是唯一,且已排序的字符串列表,不区分大小写
/// <summary>
/// UStringListCI_值都是唯一,且已排序的字符串列表,不区分大小写
/// </summary>
public class SUStringListUI_ : SUStringList_
{
public SUStringListUI_(Sortord_ sortord): base(sortord)
{
}
/// <summary>
/// 确定某元素是否在列表中
/// </summary>
/// <param name="item">查找的对象。对于引用类型,该值可以为 null。</param>
/// <returns>如果在列表中找到 item,则为 true,否则为 false。</returns>
public override bool Contains(string item)
{
if (Count == 0) return false;
if (Count == 1) return First.Data.ToLower().CompareTo(item.ToLower()) == 0;
if (Count == 2) return First.Data.ToLower().CompareTo(item.ToLower()) == 0 || First.Next.Data.ToLower().CompareTo(item.ToLower()) == 0;
int nPos = (int)Count / 2; //nPos在中间,所以无素一定要大于等于3才行
int nLeft = 0; //左边远素
int nRight = (int)Count - 1; //右边远素
DListNote_<string> ld = null;
if (_sortord == Sortord_.s_max_min)
{
while (nRight >= 0 && nLeft >= 0)
{
ld = IndexOfNote(nPos);
int iCom = item.ToLower().CompareTo(ld.Data.ToLower());
if (iCom > 0)
{
if (nRight == nLeft || nPos == nLeft)
{
return false;
}
nRight = nPos - 1;
}
else if (iCom < 0)
{
if (nRight == nLeft || nPos == nRight)
{
return false;
}
nLeft = nPos + 1;
}
else
{
return true;
}
nPos = nLeft + (nRight - nLeft + 1) / 2;
}
}
else
{
while (nRight >= 0 && nLeft >= 0)
{
ld = IndexOfNote(nPos);
int iCom = item.ToLower().CompareTo(ld.Data.ToLower());
if (iCom < 0)
{
if (nRight == nLeft || nPos == nLeft)
{
return false;
}
nRight = nPos - 1;
}
else if (iCom > 0)
{
if (nRight == nLeft || nPos == nRight)
{
return false;
}
nLeft = nPos + 1;
}
else
{
return true;
}
nPos = nLeft + (nRight - nLeft + 1) / 2;
}
}
return false;
}
}
#endregion
/// <summary>
/// 历史记录,相当于栈
/// </summary>
/// <typeparam name="T"></typeparam>
/// 创建时间:2022-03-06 最后一次修改时间:2022-04-19
public class UniqueStack_<T>
{
private DList_<T> m_List;
private int m_Capacity;
public DList_<T> List => m_List;
/// <summary>
/// 元素容量
/// </summary>
public int Capacity => m_Capacity;
/// <summary>
/// 无素个数
/// </summary>
public int Count => m_List.Count;
public UniqueStack_(int nCapacity = 15)
{
if(nCapacity <= 0)
{
lg.ShowError("容量不能小于等于 0 !");
m_Capacity = 15;
}
else
{
m_Capacity = nCapacity;
}
m_List = new DList_<T>();
}
/// <summary>
/// 添加一项
/// </summary>
/// <param name="item"></param>
/// 创建时间: 2022-04-19 最后一次修改时间:2022-04-19
public void Push(T item)
{
bool bFind = m_List.RemoveItem(item); //如果找到,则删除
if (!bFind)
{
if (m_List.Count < m_Capacity)
{
m_List.StackPush(item);
}
else
{
//插入一个Item,所有元素后移一位
m_List.StackPush(item,true);
}
}
else
{
//插入一个Item,所有元素后移一位
m_List.StackPush(item);
}
}
/// <summary>
/// 出栈
/// </summary>
public void Pop() => List.StackPop();
}
public class HistoryString_ : UniqueStack_<string>
{
public override string ToString()
{
string sResult = "";
foreach (string s in List)
{
sResult += s + "||";
}
if (sResult != "")
{
sResult = sResult.Substring(0, sResult.Length - 2);
}
return sResult;
}
public void FromString(string sVaule)
{
List.Clear();
StringList_ ls = sVaule._Split("||");
DListNote_<string> dnNote = ls.Last;
while (dnNote != null){
Push(dnNote.Data);
dnNote = dnNote.Prev;
}
}
public HistoryString_(int nCapacity = 15) : base(nCapacity) { }
}
public class HistoryStringPair : UniqueStack_<Pair_<string, string>>
{
public override string ToString()
{
string sResult = "";
foreach (Pair_<string, string> pair in List)
{
sResult += pair.First + "," + pair.Second + "||";
}
if (sResult != "")
{
sResult = sResult.Substring(0, sResult.Length - 2);
}
return sResult;
}
public void FromString(string sVaule)
{
List.Clear();
StringList_ ls1 = sVaule._Split("||");
DListNote_<string> dnNote = ls1.Last;
while (dnNote != null)
{
StringList_ ls2 = dnNote.Data._Split(",");
if (ls2.Count == 2)
{
Push(ls2[0], ls2[1]);
}
dnNote = dnNote.Prev;
}
}
public HistoryStringPair(int nCapacity = 15) : base(nCapacity) { }
public void Push(string s1, string s2) { base.Push(new Pair_<string, string>(s1, s2)); }
public Pair_<string, string> IndexOfFirst(string sFirst)
{
foreach (Pair_<string, string> pair in List)
{
if (pair.First == sFirst)
return pair;
}
return null;
}
public Pair_<string, string> IndexOfSecond(string sSecond)
{
foreach(Pair_<string, string> pair in List)
{
if(pair.Second == sSecond)
return pair;
}
return null;
}
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。