title: c# insert item in order custom linked list
body: <p>im trying to add the number 8 into my list using the InsertInOrder method</p>
  
  <p>e.g. my current list 5, 10, 12, 14, 26, 45, 52</p>
  
  <p>after inserting new node 5, 8, 10, 12, 14, 26, 45, 52</p>
  
  <p>i know i have to iterate through the list in order to find the correct position for it 
  but where do i start?</p>
  
  <pre><code>class LinkList
  {
  
  private Link list = null; //default value – empty list
  
  public void AddItem(int item) //add item to front of list
  {
      list = new Link(item, list);
  }
  
  
  public void InsertInOrder(int item)
  {
      Link temp = list;
      while (temp != null)
      {
  
          AddItem(item);
          Console.WriteLine(temp.Data);
          temp = temp.Next;
  
      }
  }
  
  public void DisplayItems() // Displays items in list
  {
      Link temp = list;
      while (temp != null)
      {
          Console.WriteLine(temp.Data);
          temp = temp.Next;
  
      }
  
  }
  </code></pre>
  
  <p>Link class:</p>
  
  <pre><code> class Link
      {
          private int data;
          private Link next;
  
          public Link(int item) //constructor with an item
          {
              data = item;
              next = null;
          }
          public Link(int item, Link list) //constructor with item and list
          {
              data = item;
              next = list;
          }
  
          public int Data //property for data
          {
              set { this.data = value; }
              get { return this.data; }
          }
  
          public Link Next //property for next
          {
              set { this.next = value; }
              get { return this.next; }
          }
      }
  }
  </code></pre>