⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 linklist.cs

📁 使用C#写的数据结构库(从链表到图)
💻 CS
字号:
using System;

namespace DataTypeDemo
{
	/// <summary>
	/// linkList 的摘要说明。
	/// </summary>
	public class linkList : dataType
	{
		protected node head;	//The linklist's head node
		//protected int length;	//The linklist's length
		//protected node current;//The current node
		protected node treil;	//The treil node

		public node Head
		{
			get{return head;}
		}

		public int Length
		{
			get{return length;}
		}

		public node Current
		{
			get{return current;}
		}

		public node Treil
		{
			get{return treil;}
		}
		
		/**
		* structure linklist
		* 
		* <PARAM>  -
		* <RETURN> -
		* <NOTES> 
		* <HISTORY> 2004/6/15 by LiJun
		*/
		public linkList()
		{
			//
			// TODO: 在此处添加构造函数逻辑
			//
			length = 0;
		}
		
		/**
		* CreateLinkList 
		* 
		* <PARAM>  -
		* <RETURN> -
		* <NOTES> 
		* <HISTORY> 2004/6/15 by LiJun
		*/
		public void CreateLinkList()
		{
			this.head = new node();
			this.treil = new node();
			this.current = null;
			this.head.Next = treil;
			//System.Windows.Forms.MessageBox.Show(this.head.Next.ToString());
			this.treil.Up = head;			
		}
		
		/**
		* CreateLinkList 
		* 
		* <PARAM>  object[] nArray
		* <RETURN> -
		* <NOTES> 
		* <HISTORY> 2004/6/15 by LiJun
		*/
		public void CreateLinkList(object[] nArray)
		{
			this.CreateLinkList(); //Create empty linklist
			if(nArray != null)
			{
				this.length = nArray.Length;
				node temp = null;
				int i = 0;
				//Create Node for ervery one Node of linklist
				foreach(object n in nArray)
				{
					if(i == 0)
					{
						head.Next = treil;
						temp = new node(n, treil, head);
						//System.Windows.Forms.MessageBox.Show(temp.ToString());
						this.head.Next = temp;
						//System.Windows.Forms.MessageBox.Show(this.head.Next.Data.ToString());
						this.treil.Up = temp;
						this.current = temp;
						i++;
					}
					else
					{
						temp = new node(n, treil, current);
						this.current.Next = temp;
						this.current = temp;
						treil.Up = temp;
						i++;
					}
				}
			}
		}
		
		/**
		* Insert a node 
		* 
		* <PARAM> object data
		* <RETURN> -
		* <NOTES> 
		* <HISTORY> 2004/6/15 by LiJun
		*/
		public void AddNode(object data)
		{
			node n = new node(data,treil,treil.Up);
			n.Up.Next = n;
			this.current = n;
			this.treil.Up = n;
			//System.Windows.Forms.MessageBox.Show(treil.Up.Up.Data.ToString());
			this.length ++;
		}
		
		/**
		* exHeadOrTreil
		* 
		* <PARAM> node n
		* <RETURN> byte
		* <NOTES> 
		* <HISTORY> 2004/6/15 by LiJun
		*/
		private byte exHeadOrTreil(node n)
		{
			if(n.Up == head)
			{
				return 1;
			}
			else if(n.Next == treil)
			{
				return 2;
			}
			else if(n.Up == head && n.Next == treil)
			{
				return 3;
			}
			else
			{
				return 0;
			}
		}
		/**
		* Insert a node 
		* 
		* <PARAM> object data,int index
		* <RETURN> -
		* <NOTES> 
		* <HISTORY> 2004/6/15 by LiJun
		*/
		public void InsertNode(object data, int index)
		{
			//serchNode return The index place
			node insNUp = this.serchNode(index);
			//System.Windows.Forms.MessageBox.Show(head.Next.Data.ToString());
			if(insNUp != null)
			{
				node insNNext = insNUp.Next;
				//insert new Node
				node newN = new node(data, insNNext, insNUp);
				insNNext.Up = newN;
				insNUp.Next = newN;
				this.current = newN;
				this.length ++;
			}
		}
		
		/**
		* Delete a node 
		* 
		* <PARAM> 
		* <RETURN> -
		* <NOTES> 
		* <HISTORY> 2004/6/15 by LiJun
		*/
		public void DeleteNode()
		{
			node n = this.treil.Up;		
			if(n != head)
			{
				n.Up.Next = n.Next;
				this.treil.Up = n.Up;
				if(n.Up != head)
				{
					
					this.current = n.Up;
				}
				else 
				{
					this.head.Next = this.treil;
					this.treil.Up = head;
					this.current = null;
				}
				n = null;
				this.length --;
			}
		}
		
		/**
		* Delete a node 
		* 
		* <PARAM> object data,int index
		* <RETURN> -
		* <NOTES> 
		* <HISTORY> 2004/6/15 by LiJun
		*/
		public void DeleteNode(int index)
		{
			node delN = this.serchNode(index);
			//byte b = this.exHeadOrTreil(delN);
			if(delN != null)
			{	
				if(delN.Up == head)
				{
					if(delN.Next == this.treil)
					{
						this.head.Next = this.treil;
						this.treil.Up = this.head;
					}
					else
					{
						this.head.Next = delN.Next;
						delN.Next.Up = this.head;
					}
				}			
				else 
				{				
					this.current = delN.Up;
					delN.Up.Next = delN.Next;
					delN.Next.Up = delN.Up;
				}
				delN = null;
				this.length --;
			}

		}
		
		/**
		* serchNode
		* 
		* <PARAM> object data
		* <RETURN> -
		* <NOTES> 
		* <HISTORY> 2004/6/15 by LiJun
		*/
		private node serchNode(object data, ref int index)
		{
			node n = head;
			while(n.Next != this.treil)
			{
				index ++;
				if(n.Next.Data == data)
				{
					return n;
				}
				n = n.Next;
			}
			return null;
		}

		private node serchNode(int index)
		{
			node n = head;
			int i = 1;
			while(i <= index)
			{
				
				n = n.Next;
				i++;
			}
			this.current = n;
			return n;
		}
		
		/**
		* Get Find Data
		* 
		* <PARAM> int index
		* <RETURN> -
		* <NOTES> 
		* <HISTORY> 2004/6/15 by LiJun
		*/
		public override object GetFindData(int index)
		{
			node n = this.serchNode(index);
			//System.Windows.Forms.MessageBox.Show(n.Data.ToString());
			object data = null;
			if(n != null )
			{
				data = n.Data;
			}
			else
			{
				data = null;
			}
			return data;
		}
		
		/**
		* Get Node Index
		* 
		* <PARAM> int index
		* <RETURN> -
		* <NOTES> 
		* <HISTORY> 2004/6/15 by LiJun
		*/
		public object GetNodeIndex(object data)
		{
			int index = 0;
			this.serchNode(data, ref index);
			return index;
		}

		/**
		*SetEmpty
		* 
		* <PARAM> 
		* <RETURN> -
		* <NOTES> 
		* <HISTORY> 2004/6/15 by LiJun
		*/
		public override void SetEmpty()
		{
			this.current = null;
			this.head = null;
			this.treil = null;
			this.length = 0;
			CreateLinkList();
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -