What are the classes that construct linear tables in C #
This article will explain in detail what classes are used to construct linear tables in C#. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
Let's take a look at the C # data structures and algorithms that construct the code for the class of the linear table:
Public interface IListDS < T > {int GetLength (); void Clear (); bool IsEmpty (); bool IsFull (); void Append (T item); void Insert (T item, int I); T Delete (int I); T GetElem (int I); string Locate (T value);} public class TList < T >: IListDS < T > {private T [] _ list; private int _ len Private int _ lastOne; public T this [int length] {get {return _ list [length];} set {_ list [length] = value;}} public int List {get {return _ lastOne;}} public int Maxsize {get {return _ len;} set {_ len = value } public TList (int size) {_ list = new T [size]; _ len = size; _ lastOne =-1;} public int GetLength () {return _ lastOne + 1;} public bool IsEmpty () {if (_ lastOne = =-1) {return true } else {return false;}} public void Clear () {_ lastOne =-1;} public bool IsFull () {if (_ lastOne = = _ len-1) {return true;} else {return false }} public void Append (T item) {if (IsFull ()) {throw new ArgumentOutOfRangeException ("The list is full!");} _ list [+ + _ lastOne] = item } public void Insert (T item, int I) {if (IsFull ()) {throw new ArgumentOutOfRangeException ("The list is full!");} if (I < 0 | | I > _ len) {throw new ArgumentOutOfRangeException ("Position Error!") } if (I = = _ lastOne) {_ list [+ _ lastOne] = item;} else {for (int j = I; j < _ len-1; jlist +) {_ list [j + 1] = _ list [j] } _ list [I] = item;} + _ lastOne;} public T Delete (int I) {T t = default (T); if (IsEmpty ()) {throw new ArgumentNullException ("T", "List is empty!") } if (I < 0 | | I > _ lastOne) {throw new ArgumentOutOfRangeException ("T", "Position is Error!");} if (I = = _ lastOne) {t = _ list [_ lastOne-1];} else {t = _ list [_ lastOne] For (int j = I; j < _ lastOne; jacks +) {_ list [j] = _ list [j + 1];}}-- _ lastOne; return t } public T GetElem (int I) {if (IsEmpty ()) {throw new ArgumentNullException ("T", "List is empty!");} if (I < 0 | | I > _ len) {throw new ArgumentOutOfRangeException ("Position is Error!");} return _ list [I] } public string Locate (T value) {if (IsEmpty ()) {throw new ArgumentNullException ("T", "List is empty!");} int I = 0; for (I = 0; I < _ len) If +) {if (value.Equals (_ list [I])) {break;}} if (I > = _ len) {return "- 1";} return i.ToString ();}}
C # data structures and algorithms call linear table operations of classes that construct linear tables:
TList < string > TL = new TList < string > (5) {}; TL.Append ("A"); TL.Append ("B"); about "what are the classes that construct linear tables in C#" this article is here. I hope the above content can be of some help to you, so that you can learn more knowledge. If you think the article is good, please share it out for more people to see.