コード例 #1
0
        public override string ToString()
        {
            DoubleLinkedItem currentLink = _first;
            StringBuilder    builder     = new StringBuilder();

            while (currentLink != null)
            {
                builder.Append(currentLink);
                currentLink = currentLink.NextLink;
            }
            return(builder.ToString());
        }
コード例 #2
0
        public DoubleLinkedItem Insert(string title)
        {
            // Creates a link, sets its link to the first item and then makes this the first item in the list.
            DoubleLinkedItem link = new DoubleLinkedItem(title);

            link.NextLink = _first;
            if (_first != null)
            {
                _first.PreviousLink = link;
            }
            _first = link;
            return(link);
        }
コード例 #3
0
        public DoubleLinkedItem Delete()
        {
            // Gets the first item, and sets it to be the one it is linked to
            DoubleLinkedItem temp = _first;

            if (_first != null)
            {
                _first = _first.NextLink;
                if (_first != null)
                {
                    _first.PreviousLink = null;
                }
            }
            return(temp);
        }
コード例 #4
0
        ///// New operations
        public void InsertAfter(DoubleLinkedItem link, string title)
        {
            if (link == null || string.IsNullOrEmpty(title))
            {
                return;
            }
            DoubleLinkedItem newLink = new DoubleLinkedItem(title);

            newLink.PreviousLink = link;
            // Update the 'after' link's next reference, so its previous points to the new one
            if (link.NextLink != null)
            {
                link.NextLink.PreviousLink = newLink;
            }
            // Steal the next link of the node, and set the after so it links to our new one
            newLink.NextLink = link.NextLink;
            link.NextLink    = newLink;
        }
コード例 #5
0
 public DoubleLinkedList()
 {
     _first = null;
 }