Exemplo n.º 1
0
        /// <summary>
        /// Gets the first pair in the linked list
        /// </summary>
        /// <returns></returns>
        public LinkedPair <KeyType, DataType> GetFirstLinkedPairInList()
        {
            LinkedPair <KeyType, DataType> current = this;

            while (true)
            {
                LinkedPair <KeyType, DataType> previous = current.GetPrevious();
                if (previous == null)
                {
                    break;
                }
                else
                {
                    current = previous;
                }
            }

            return(current);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Search for a <see cref="LinkedPair{KeyType, DataType}"/> with a specified key that is linked with this one, only searching backwards in the list
        /// </summary>
        /// <param name="key">Search key</param>
        /// <returns>Matched pair. Can be null</returns>
        public LinkedPair <KeyType, DataType> GetLinkedPairWithKeyInListBackwardSearch(KeyType key)
        {
            if (this.key.Equals(key))
            {
                return(this);
            }

            for (LinkedPair <KeyType, DataType> previous = this.GetPrevious(); previous != null; previous = previous.GetPrevious())
            {
                if (previous.key.Equals(key))
                {
                    return(previous);
                }
            }

            return(null);
        }