c# - Chain linked classes -


i have created long chains of classes, each link(class) knowing next , previous link. see great advantage on arrays when index not important.

public class chainlink {     public chainlink previouslink, nextlink;      // accessors here } 

questions :

  1. what technique called? (i don't know search)
  2. is there .net class same thing?
  3. is there noticeable performance impact vs. array or list?

example of accessors use

assign chain :

    public chainlink nextlink {         get{ return _nextlink;}         set {             _nextlink = value;             if (value != null)                 value._previouslink = this;         }     }      public void insertnext (chainlink link)     {         link.nextlink = _nextlink;         link.previouslink = this;     } 

shortening chain :

if un-assign next link of chain, leaving remaining links un-referenced main program, garbage collector dispose of data me.

testing circular referencing :

    public bool iscircular ()     {         chainlink link = this;         while (link != null) {             link = link._nextlink;             if (link == this)                 return true;         }         return false;     } 

offset index :

    public chainlink [int offset] {         {             if (offset > 0 && _nextlink != null)                 return _nextlink [offset - 1];             if (offset < 0 && _previouslink != null)                 return _previouslink [offset + 1];             return this;         }     } 

1) structure called double linked list

2) implementation exists in c# through linkedlist

3) there lot of articles on topic : here or this post


Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -