예제 #1
0
        public string DisplayBackward()
        {
            StringBuilder result   = new StringBuilder();
            DDLinkedList  traverse = runner;

            while (traverse != null)
            {
                result.Append($"Key = {traverse.Data} Value = {traverse.Data} \n");
                traverse = traverse.Previous;
            }
            return(result.ToString());
        }
예제 #2
0
        public string DisplayForward()
        {
            StringBuilder result   = new StringBuilder();
            DDLinkedList  traverse = start;

            while (traverse != null)
            {
                result.Append($"Key = {traverse.Data} Value = {traverse.Data} \n");
                traverse = traverse.Next;
            }
            return(result.ToString());
        }
예제 #3
0
 public void Put(string key, string value)
 {
     temp = null;
     cacheStorage.TryGetValue(key, out temp);
     if (temp != null)
     {
         Get(key);
         temp.Data = value;
     }
     else
     {
         if (cacheStorage.Count == capacity)
         {
             cacheStorage.Remove(start.Key);
             if (start.Next == null)
             {
                 start.Data = value;
             }
             else
             {
                 start          = start.Next;
                 start.Previous = null;
                 runner.Next    = new DDLinkedList()
                 {
                     Key = key, Data = value, Previous = runner
                 };
                 runner = runner.Next;
             }
         }
         else
         {
             if (start == null)
             {
                 start = new DDLinkedList()
                 {
                     Key = key, Data = value
                 };
                 runner = start;
             }
             else
             {
                 runner.Next = new DDLinkedList()
                 {
                     Key = key, Data = value, Previous = runner
                 };
                 runner = runner.Next;
             }
         }
         cacheStorage[key] = runner;
     }
 }
예제 #4
0
        public string Get(string key)
        {
            temp = null;
            cacheStorage.TryGetValue(key, out temp);

            if (temp == null)
            {
                return("-1");
            }


            if (start.Next == null)
            {
                return(start.Data);
            }
            else if (temp.Next == null)
            {
                return(temp.Data);
            }
            else if (temp.Key == start.Key) // if data is in start location;
            {
                start          = start.Next;
                start.Previous = null;
                //temp.Previous = new DDLinkedList();
            }
            else if (temp.Next != null) //
            {
                temp.Previous.Next = temp.Next;
                temp.Next.Previous = temp.Previous;
            }

            temp.Next     = null;
            temp.Previous = runner;
            runner.Next   = temp;
            runner        = runner.Next;
            return(temp.Data);
        }