public void AddAtEnd(ObjectCell newCell)
 {
     while (Top.Next != null)
     {
         Top = Top.Next;
     }
     Top.Next     = newCell;
     newCell.Next = null;
 }
 public void Iterate(ObjectCell top)
 {
     while (top != null)
     {
         Console.WriteLine(top.Value);
         top = top.Next;
     }
     Console.WriteLine("End of list\n");
 }
        public ObjectCell FindCell(object value)
        {
            ObjectCell top = Top;

            while (top != null)
            {
                if (top.Value == value)
                {
                    return(top);
                }
                top = top.Next;
            }
            return(null);
        }
        public SinglyLinkedListExample()
        {
            var singlyLinkedList = new SinglyLinkedList();

            singlyLinkedList.AddAtEnd(new ObjectCell("some value"));
            singlyLinkedList.AddAtEnd(new ObjectCell("some value1"));
            singlyLinkedList.AddAtBeginning(new ObjectCell("some Valeu 2"));

            var iterator = new SinglyLinkedListIterator();

            iterator.Iterate(singlyLinkedList.Top);

            ObjectCell foundCell = singlyLinkedList.FindCell("some value");        //O(N)

            singlyLinkedList.InsertCell(foundCell, new ObjectCell("Inser value")); //O(1)
            iterator.Iterate(singlyLinkedList.Top);

            singlyLinkedList.DeleteAfter(foundCell.Next);
            iterator.Iterate(singlyLinkedList.Top);
        }
 public void DeleteAfter(ObjectCell afterCell)
 {
     afterCell.Next = afterCell.Next.Next;
 }
 public void InsertCell(ObjectCell afterCell, ObjectCell newCell)
 {
     newCell.Next   = afterCell.Next;
     afterCell.Next = newCell;
 }
 public void AddAtBeginning(ObjectCell newCell)
 {
     newCell.Next = Top.Next;
     Top.Next     = newCell;
 }
 public SinglyLinkedList()
 {
     Top      = new ObjectCell(null);
     Top.Next = null;
 }