?? list.cs
字號:
namespace List
{
//鏈表類
public class Clist
{
protected ListNode Head; //頭結點
protected ListNode p; //當前結點
protected int ListLen;
public Clist()
{
Head=null;
p=null;
ListLen=0;
}
~Clist(){}
/*public ListNode DestoryList()
{
}*/
/// <summary>
/// 是否在鏈頭
/// </summary>
public bool IsBof()
{
if (Head==p)
{
return true;
}
return false;
}
/// <summary>
///是否在鏈尾
/// </summary>
public bool IsEof()
{
if(p.Next==null)
return true;
return false;
}
/// <summary>
/// 清空鏈表
/// </summary>
public void ClearList()
{
Head=null;
p=null;
ListLen=0;
return;
}
/// <summary>
/// 鏈表是否為空
/// </summary>
public bool ListEmpty()
{
if(ListLen==0)
return true;
return false;
}
/// <summary>
/// 鏈表長度
/// </summary>
public int ListLength
{
get{return ListLen;}
}
/// <summary>
/// 指針后移
/// </summary>
public void MoveNext()
{
if(!IsEof())
{
p=p.Next;
}
return;
}
/// <summary>
/// 指針前移
/// </summary>
public void MovePrev()
{
if(!IsBof())p=p.Previous;
return;
}
/// <summary>
/// 指針移到表頭
/// </summary>
public void MoveFirst()
{
p=Head;
return;
}
/// <summary>
/// 返回指定位置結點的值
/// </summary>
public int GetElem(int i)
{
ListNode move;
if(!ListEmpty() && i>=1 && i<=ListLength)
{
int j;
move=Head;
for(j=1;j<i;j++)
//while(move!=null)
{
move=move.Next;
}
return move.Value;
}
return 0;
}
//public int PriorElem(ListNode ThisList,int cur_e){}
//public int NextElem(ListNode ThisList,int cur_e){}
/// <summary>
/// 添加新結點
/// </summary>
public void AppendNode(int e)
{
ListNode NewNode=new ListNode(e);
if(ListEmpty())
{
Head=NewNode;
p=NewNode;
}
else
{
p.Next=NewNode;
NewNode.Previous=p;
p=NewNode;
}
ListLen++;
return;
}
/// <summary>
/// 前插結點
/// </summary>
public void ListInsert(int i,int e)
{
ListNode NewNode=new ListNode(e);
ListNode q;
ListNode move;
int j;
if(!ListEmpty() && i>=1 && i<=ListLength)
{
if(i==1)
{
Head.Previous =NewNode;
NewNode.Next =Head;
Head=NewNode;
p=NewNode;
ListLen++;
}
else
{
move=Head;
for(j=1;j<i;j++)
//while(move.Next!=null)
{
move=move.Next;
}
q=move.Previous;
NewNode.Next =move;
move.Previous =NewNode;
q.Next =NewNode;
NewNode.Previous =q;
move=NewNode;
p=NewNode;
ListLen++;
}
}
else
{
Head=NewNode;
p=NewNode;
}
return;
}
/// <summary>
/// 刪除指定位置的結點
/// </summary>
public void ListDelete(int i)
{
ListNode q;
int j;
if(!ListEmpty() && i>=1 && i<=ListLength)
{
if(i==1)
{
q=Head.Next;
q.Previous =null;
Head.Next=null;
Head=q;
}
else
{
if(i<ListLength)
{
MoveFirst();
for(j=1;j<=i;j++)
MoveNext();
q=p.Next;
q.Previous =p.Previous;
p.Previous.Next=q;
p=q;
}
else
{
MoveFirst();
for(j=1;j<=i;j++)
MoveNext();
q=p.Previous ;
q.Next=null;
p=q;
}
}
ListLen--;
}
}
/// <summary>
/// 判斷鏈表中是否存在e
/// </summary>
public bool Isin(int e)
{
bool bl=false;
ListNode move;
move=Head;
while(move!=null)
//for(i=1;i<=ListLength;i++)
{
if(move.Value==e)
{
bl=true;
break;
}
else
{
move=move.Next;
}
}
return bl;
}
/// <summary>
/// 打印鏈表的所有元素
/// </summary>
public string PrintList()
{
ListNode move;
string strtext="";
move=Head;
while(move!=null)
{
strtext=strtext + move.Value.ToString() + ",";
move=move.Next;
}
return strtext;
}
/// <summary>
/// 取當前指針的值(多項式的指數)
/// </summary>
public int ThisValue()
{
if(!ListEmpty())
return p.Value;
return 0;
}
/// <summary>
/// 設置當前指針所在的元素值(多項式指數)
/// </summary>
public void SetValue(int e)
{
if(p!=null)p.Value=e;
return;
}
/// <summary>
/// 設置當前指針所在的系數值
/// </summary>
public void SetCoef(float c)
{
if(p!=null)p.Coef=c;
return;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -