自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

C#數(shù)據(jù)結構與算法之構造線性表的類淺析

開發(fā) 后端 算法
C#數(shù)據(jù)結構與算法之構造線性表的類有哪些呢?他們是怎么實現(xiàn)的呢?那么本文就向你介紹這方面的內(nèi)容。

C#數(shù)據(jù)結構與算法之構造線性表的類有哪些呢?C#數(shù)據(jù)結構與算法之構造線性表的類是如何使用的呢?

讓我們來看看C#數(shù)據(jù)結構與算法之構造線性表的類的代碼使用:

  1. public interface IListDS﹤T﹥   
  2. {  
  3.     int GetLength();  
  4.     void Clear();  
  5.     bool IsEmpty();  
  6.     bool IsFull();  
  7.     void Append(T item);  
  8.     void Insert(T item, int i);  
  9.     T Delete(int i);  
  10.     T GetElem(int i);  
  11.     string Locate(T value);  
  12.  
  13. }  
  14.  
  15. public class TList﹤T﹥ : IListDS﹤T﹥  
  16. {  
  17.     private T[] _list;  
  18.     private int _len;  
  19.     private int _lastOne;  
  20.  
  21.     public T this[int length]  
  22.     {  
  23.         get { return _list[length]; }  
  24.         set { _list[length] = value; }  
  25.     }  
  26.  
  27.     public int List  
  28.     {  
  29.         get { return _lastOne; }  
  30.     }  
  31.  
  32.     public int Maxsize  
  33.     {  
  34.         get { return _len; }  
  35.         set { _len = value; }  
  36.     }  
  37.  
  38.     public TList(int size)  
  39.     {  
  40.         _list = new T[size];  
  41.         _len = size;  
  42.         _lastOne = -1;  
  43.     }  
  44.  
  45.     public int GetLength()  
  46.     {  
  47.         return _lastOne + 1;  
  48.     }  
  49.  
  50.     public bool IsEmpty()  
  51.     {  
  52.         if (_lastOne == -1)  
  53.         { return true; }  
  54.         else 
  55.         { return false; }  
  56.     }  
  57.  
  58.     public void Clear()  
  59.     {  
  60.         _lastOne = -1;  
  61.     }  
  62.  
  63.     public bool IsFull()  
  64.     {  
  65.         if (_lastOne == _len - 1)  
  66.         { return true; }  
  67.         else 
  68.         { return false; }  
  69.     }  
  70.  
  71.     public void Append(T item)  
  72.     {  
  73.         if (IsFull())  
  74.         {   
  75.             throw new ArgumentOutOfRangeException("The list is full!");   
  76.         }  
  77.         _list[++_lastOne] = item;          
  78.     }  
  79.  
  80.     public void Insert(T item, int i)  
  81.     {  
  82.         if (IsFull())  
  83.         {  
  84.             throw new ArgumentOutOfRangeException("The list is full!");  
  85.         }  
  86.         if (i ﹤ 0 || i ﹥ _len)  
  87.         {  
  88.             throw new ArgumentOutOfRangeException("Position Error!");  
  89.         }  
  90.  
  91.         if (i == _lastOne)  
  92.         {  
  93.             _list[++_lastOne] = item;  
  94.         }  
  95.         else 
  96.         {  
  97.             for (int j = i; j ﹤ _len - 1; j++)  
  98.             {  
  99.                 _list[j + 1] = _list[j];  
  100.             }  
  101.             _list[i] = item;  
  102.         }  
  103.         ++_lastOne;  
  104.     }  
  105.  
  106.     public T Delete(int i)   
  107.     {  
  108.         T t = default(T);  
  109.         if (IsEmpty())  
  110.         {  
  111.             throw new ArgumentNullException("T""List is empty!");  
  112.         }  
  113.         if (i ﹤ 0 || i ﹥ _lastOne)  
  114.         {  
  115.             throw new ArgumentOutOfRangeException("T""Position is Error!");  
  116.         }  
  117.         if (i == _lastOne)  
  118.         {  
  119.             t = _list[_lastOne - 1];  
  120.         }  
  121.         else 
  122.         {  
  123.             t = _list[_lastOne];  
  124.             for (int j = i; j ﹤ _lastOne; j++)  
  125.             {  
  126.                 _list[j] = _list[j + 1];  
  127.             }  
  128.         }  
  129.         --_lastOne;  
  130.         return t;  
  131.     }  
  132.  
  133.     public T GetElem(int i)  
  134.     {  
  135.         if (IsEmpty())  
  136.         {  
  137.             throw new ArgumentNullException("T""List is empty!");  
  138.         }  
  139.         if (i ﹤ 0 || i ﹥ _len)  
  140.         {  
  141.             throw new ArgumentOutOfRangeException("Position is Error!");  
  142.         }  
  143.  
  144.         return _list[i];  
  145.     }  
  146.  
  147.     public string Locate(T value)  
  148.     {  
  149.         if (IsEmpty())  
  150.         {  
  151.             throw new ArgumentNullException("T""List is empty!");  
  152.         }  
  153.         int i = 0;  
  154.         for (i = 0; i ﹤ _len; i++)  
  155.         {  
  156.             if (value.Equals(_list[i]))  
  157.             {   
  158.                 break;  
  159.             }  
  160.         }  
  161.         if (i ﹥= _len)  
  162.         {  
  163.             return "-1";  
  164.         }  
  165.         return i.ToString();  
  166.     }  

C#數(shù)據(jù)結構與算法中構造線性表的類之調(diào)用線性表的操作:

  1. TList﹤string﹥ TL = new TList﹤string﹥(5) { };  
  2.  
  3. TL.Append("A");  
  4.  
  5. TL.Append("B"); 

大家多多討論,有不對的地方請多多指正。

C#數(shù)據(jù)結構與算法之構造線性表的類方面的內(nèi)容就向大家介紹到這里,希望對大家學習C#數(shù)據(jù)結構與算法之構造線性表的類有所幫助。

【編輯推薦】

  1. C#算法應用之高斯消元法實現(xiàn)
  2. C#二叉樹遍歷算法實現(xiàn)淺析
  3. C#算法之約瑟夫環(huán)算法淺析
  4. C#數(shù)據(jù)結構與算法之線性表淺析
  5. C#數(shù)據(jù)結構與算法之順序表淺析
責任編輯:仲衡 來源: cnblogs
相關推薦

2009-08-11 14:14:42

C#數(shù)據(jù)結構與算法

2023-11-06 06:43:23

單鏈表查詢數(shù)據(jù)結構

2009-08-11 14:30:32

C#數(shù)據(jù)結構與算法

2009-08-11 14:43:42

C#數(shù)據(jù)結構與算法

2009-08-11 14:51:11

C#數(shù)據(jù)結構與算法

2018-06-06 08:54:23

數(shù)據(jù)結構存儲

2009-08-12 18:35:17

C#數(shù)據(jù)結構

2009-08-03 17:38:12

排序算法C#數(shù)據(jù)結構

2021-07-11 12:06:43

python數(shù)據(jù)結構

2020-06-09 08:13:15

PHP數(shù)據(jù)結構

2023-03-13 10:08:31

數(shù)據(jù)結構算法

2021-04-20 09:18:41

順序存儲結構

2009-06-24 09:52:21

哈希表

2009-08-27 16:18:47

C#類C#結構體

2009-08-13 17:30:30

C#構造函數(shù)

2023-02-08 07:52:36

跳躍表數(shù)據(jù)結構

2017-08-31 09:45:43

JavaArrayList數(shù)據(jù)

2009-08-11 09:19:52

C#選擇排序C#算法

2009-08-13 14:06:37

C#結構體結構體和類的區(qū)別

2009-08-13 17:38:42

C#構造函數(shù)
點贊
收藏

51CTO技術棧公眾號