예제 #1
0
 public void AddBefore(Person value, LinkedListItem point)
 {
     if (Head == null)
         AddFirst(value);
     else
     {
         var current = new LinkedListItem {Data = value};
         current.Prev = point.Prev;
         point.Prev.Next = current;
         current.Next = point;
         point.Prev = current;
     }
 }
예제 #2
0
 public void AddLast(Person value)
 {
     if (Head == null)
     {
         Head = new LinkedListItem {Data = value};
         Tail = Head;
     }
     else
     {
         Tail.Next = new LinkedListItem {Data = value, Prev = Tail};
         Tail = Tail.Next;
     }
     Count++;
 }
예제 #3
0
 public void AddFirst(Person value)
 {
     if (Head == null)
     {
         Head = new LinkedListItem { Data = value };
         Tail = Head;
     }
     else
     {
         Head.Prev = new LinkedListItem {Data = value, Next = Head};
         Head = Head.Next;
     }
     Count++;
 }
예제 #4
0
 public static void FindMenu()
 {
     Console.WriteLine("Введи тип поиска (age, height, weight, name)");
     string type = Console.ReadLine();
     Console.WriteLine("Введи ключ");
     string key = Console.ReadLine();
     var temp = new LinkedListItem();
     if (type == "name")
         temp = myList.FindString(key);
     else
         temp = myList.FindInt(type, int.Parse(key));
     if (temp != null)
         Console.WriteLine("Имя: {0}, возраст: {1}, рост: {2}, вес: {3}", temp.Data.Name, temp.Data.Age.ToString(),
                       temp.Data.Height.ToString(), temp.Data.Weight.ToString());
     else FindMenu();
 }
예제 #5
0
 public void QuickSort(string key, LinkedListItem left, LinkedListItem right)
 {
     LinkedListItem start, current;
     if (left == right) return;
     start = left;
     current = start.Next;
     while (true)
     {
         switch (key)
         {
             case "age":
                 if (start.Data.Age < current.Data.Age)
                     Swap(start.Data, current.Data);
                 break;
             case "height":
                 if (start.Data.Height < current.Data.Height)
                     Swap(start.Data, current.Data);
                 break;
             case "weight":
                 if (start.Data.Weight < current.Data.Weight)
                     Swap(start.Data, current.Data);
                 break;
             case "name":
                 if (start.Data.Name[0] < current.Data.Name[0])
                     Swap(start.Data, current.Data);
                 break;
         }
         if (current == right) break;
         current = current.Next;
     }
     Swap(left.Data, current.Data);
     LinkedListItem old = current;
     current = current.Prev;
     if (current != null)
         if ((left.Prev != current) && (current.Next != left))
             QuickSort(key, left, current);
     current = old;
     current = current.Next;
     if (current != null)
         if ((current.Prev != right) && (right.Next != current))
             QuickSort(key, current, right);
 }
예제 #6
0
 public Person PickLast()
 {
     if (Head != null)
     {
         Person value = Tail.Data;
         if (Tail != Head)
         {
             Tail = Tail.Prev;
             Tail.Next.Prev = null;
             Tail.Next = null;
         }
         else
         {
             Tail = null;
         }
         Count--;
         return value;
     }
     else return null;
 }