private void AddWords(DoubleLinkedList <string> list)
 {
     list.Add("Ndumiso Chamane");
     list.Add("Mfundo Mkhize");
     list.Add("Ntuthuko Cele");
     list.Add("Njabulo Khuzwayo");
 }
Пример #2
0
        public void DoubleLinkedListRemoveValues()
        {
            var    keyExist         = false;
            string valueToAdd       = "1";
            string valueToRemove    = "2";
            var    doubleLinkedList = new DoubleLinkedList <string>();

            doubleLinkedList.Add(valueToAdd);
            doubleLinkedList.Add(valueToRemove);

            var listValues = doubleLinkedList.GetListValues();

            if (listValues != null && listValues.Count > 0)
            {
                keyExist = listValues.Contains(valueToRemove);
            }

            Assert.IsTrue(keyExist, "Value adding to list failed");

            doubleLinkedList.Remove(valueToRemove);

            listValues = doubleLinkedList.GetListValues();
            if (listValues != null && listValues.Count > 0)
            {
                keyExist = !listValues.Contains(valueToRemove);
            }
            else
            {
                Assert.Fail("Remove values test fails");
            }

            Assert.IsTrue(keyExist, "Value was not removed from list successfully");
        }
Пример #3
0
        public void AllMethodsTest(int[] inputArray, int[] expectedArray)
        {
            DoubleLinkedList expected = new DoubleLinkedList(expectedArray);
            DoubleLinkedList actual   = new DoubleLinkedList(inputArray);

            actual.Add(8);
            actual.AddAtFirstIndex(100);
            actual.AddAtIndex(20, 3);
            actual.Remove();
            actual.RemoveAtFirstIndex();
            actual.RemoveByIndex(1);
            actual.Add(9);
            actual.RemoveLastValues(3);
            actual.AddAtFirstIndex(100);
            actual.AddAtFirstIndex(25);
            actual.RemoveFirstValues(2);
            actual.AddListByIndex(new DoubleLinkedList(new int[] { 2, 3, 4, 5 }), 1);
            actual.RemoveValuesByIndex(5, 2);
            actual.Reverse();
            actual.SortAscending();
            actual.SortDescending();
            actual.AddList(new DoubleLinkedList(new int[] { 100, 200 }));
            actual.AddListAtBeginning(new DoubleLinkedList(new int[] { 99, 88, 77 }));
            actual.AddAtFirstIndex(100);
            Assert.AreEqual(expected, actual);
        }
 public void Arrange()
 {
     list = new DoubleLinkedList <string>();
     list.Add(first);
     list.Add(second);
     list.Add(third);
     size = list.Count;
 }
        public void ToString_ContainsAddedValues()
        {
            var list = new DoubleLinkedList <string>();

            list.Add("india");
            list.Add("japan");

            Assert.IsTrue(list.ToString().Contains("india"));
            Assert.IsTrue(list.ToString().Contains("japan"));
        }
Пример #6
0
        public void DLL_AddTest()
        {
            DoubleLinkedList <int> list = new DoubleLinkedList <int>();

            Assert.AreEqual(0, list.Count);

            list.Add(4);
            list.Add(3);

            Assert.AreEqual(2, list.Count);
            Assert.AreEqual(4, list.Head.Value);
            Assert.AreEqual(3, list.Head.Next.Value);
        }
        public void contains_does_not_find_value_in_list()
        {
            // assemble
            var list = new DoubleLinkedList<int>();

            // act
            list.Add(5);
            list.Add(15);
            list.Add(45);

            // assert
            Assert.AreEqual(false, list.Contains(99));
        }
        public void AddTest()
        {
            DoubleLinkedList <int> list = new DoubleLinkedList <int>();

            Assert.AreNotEqual(null, list);
            Assert.AreEqual(0, list.Count);
            list.Add(10);
            Assert.AreEqual(1, list.Count);
            for (int i = 0; i < 100; ++i)
            {
                list.Add(i);
            }
            Assert.AreEqual(101, list.Count);
        }
Пример #9
0
        public void DLL_InsertTest()
        {
            DoubleLinkedList <int> list = new DoubleLinkedList <int>();

            Assert.ThrowsException <IndexOutOfRangeException>(() => list.Insert(6, -1));

            list.Add(4);
            list.Add(3);

            list.Insert(6, 1);
            Assert.ThrowsException <IndexOutOfRangeException>(() => list.Insert(6, 99));

            Assert.AreEqual(3, list.Count);
            Assert.AreEqual(6, list.Get(1));
        }
        public void contains_finds_value_in_list()
        {
            // assemble
            var list = new DoubleLinkedList<int>();

            // act
            list.Add(5);
            list.Add(15);
            list.Add(45);

            // assert
            Assert.AreEqual(true, list.Contains(5));
            Assert.AreEqual(true, list.Contains(15));
            Assert.AreEqual(true, list.Contains(45));
        }
        public IActionResult Buscar()
        {
            if (F.verificar == 0)
            {
                F.verificar = 1;
                Cargardatos();
            }
            DoubleLinkedList <Paciente> vista = new DoubleLinkedList <Paciente>();

            for (int i = 1; i <= F.hospitales.Count2(); i++)
            {
                Hospitales Temphospital = new Hospitales();
                Temphospital = F.hospitales.GetbyIndex(i);
                var Temparbol = new ArbolDePrioridad <LlaveArbolPrioridad>(LlaveArbolPrioridad.Compare_Llave_Arbol);

                if (!Temphospital.Registrar.isempty())
                {
                    Temparbol = Temphospital.Registrar.Clone();
                    while (!Temparbol.isempty())
                    {
                        var templlave = new LlaveArbolPrioridad();
                        templlave = Temparbol.Remove();
                        vista.Add(Temphospital.Pacientes.Find(Convert.ToString(templlave.CodigoHash)));
                    }
                }
                if (!Temphospital.vacunados.isempty())
                {
                    Temparbol = Temphospital.vacunados.Clone();
                    while (!Temparbol.isempty())
                    {
                        var templlave = new LlaveArbolPrioridad();
                        templlave = Temparbol.Remove();
                        vista.Add(Temphospital.PacientesVacunados.Find(Convert.ToString(templlave.CodigoHash)));
                    }
                }
                if (!Temphospital.Espera.isempty())
                {
                    Temparbol = Temphospital.Espera.Clone();
                    while (!Temparbol.isempty())
                    {
                        var templlave = new LlaveArbolPrioridad();
                        templlave = Temparbol.Remove();
                        vista.Add(Temphospital.Pacientes.Find(Convert.ToString(templlave.CodigoHash)));
                    }
                }
            }
            return(View(vista));
        }
        public IActionResult Vacunacion2()
        {
            PacienteComp Comparador = Hospitales.Compare_Municipio;
            Hospitales   hospital   = new Hospitales();

            hospital = F.hospitales.Find(m => Comparador(m, HttpContext.Session.GetString("municipio")) == 0);

            restablecerfechas2();
            DoubleLinkedList <Paciente>            TempView  = new DoubleLinkedList <Paciente>();
            ArbolDePrioridad <LlaveArbolPrioridad> TempArbol = new ArbolDePrioridad <LlaveArbolPrioridad>(LlaveArbolPrioridad.Compare_Llave_Arbol);

            if (hospital.Espera.isempty())
            {
                return(View(TempView));
            }
            TempArbol = hospital.Espera.Clone();
            do
            {
                LlaveArbolPrioridad Temp = new LlaveArbolPrioridad();
                Temp = TempArbol.Remove();
                Paciente ViewVacunar = new Paciente();
                ViewVacunar = hospital.Pacientes.Find(Convert.ToString(Temp.CodigoHash));
                TempView.Add(ViewVacunar);
            } while (!TempArbol.isempty());
            return(View(TempView));
        }
        public IActionResult Index()
        {
            var          ViewPaciente = new DoubleLinkedList <Paciente>();
            PacienteComp Comparador   = Hospitales.Compare_Municipio;
            Hospitales   hospital     = new Hospitales();

            ;
            hospital = F.hospitales.Find(m => Comparador(m, HttpContext.Session.GetString("municipio")) == 0);
            ArbolDePrioridad <LlaveArbolPrioridad> Temparbol = new ArbolDePrioridad <LlaveArbolPrioridad>(LlaveArbolPrioridad.Compare_Llave_Arbol);

            if (hospital.Registrar.isempty())
            {
                return(View(ViewPaciente));
            }
            Temparbol = hospital.Registrar.Clone();
            LlaveArbolPrioridad Tempprioridad;

            do
            {
                Tempprioridad = new LlaveArbolPrioridad();
                if (!Temparbol.isempty())
                {
                    Tempprioridad = Temparbol.Remove();
                    if (Tempprioridad != null)
                    {
                        Paciente TempPaciente = new Paciente();
                        TempPaciente           = hospital.Pacientes.Find(Convert.ToString(Tempprioridad.CodigoHash));
                        TempPaciente.Prioridad = Tempprioridad.Prioridad;
                        ViewPaciente.Add(TempPaciente);
                    }
                }
            } while (Tempprioridad.CodigoHash != 0);
            return(View(ViewPaciente));
        }
Пример #14
0
        public void DLL_CountTest()
        {
            DoubleLinkedList <int> list = new DoubleLinkedList <int>();

            Assert.AreEqual(0, list.Count);

            list.Add(4);
            list.Add(3);

            Assert.AreEqual(2, list.Count);

            list.Add(2);
            list.Add(1);

            Assert.AreEqual(4, list.Count);
        }
        public IActionResult Realizarinjeccion()
        {
            PacienteComp Comparador = Hospitales.Compare_Municipio;
            Hospitales   hospital   = new Hospitales();

            hospital = F.hospitales.Find(m => Comparador(m, HttpContext.Session.GetString("municipio")) == 0);

            ArbolDePrioridad <LlaveArbolPrioridad> TempArbol = new ArbolDePrioridad <LlaveArbolPrioridad>(LlaveArbolPrioridad.Compare_Llave_Arbol);

            if (hospital.Espera.isempty())
            {
                return(RedirectToAction("Vacunacion2"));
            }
            TempArbol = hospital.Espera.Clone();
            DoubleLinkedList <Paciente> ViewVacunacion = new DoubleLinkedList <Paciente>();

            for (int i = 0; i < hospital.CantidadPasar; i++)
            {
                if (!TempArbol.isempty())
                {
                    LlaveArbolPrioridad Templlave = new LlaveArbolPrioridad();
                    Templlave = TempArbol.Remove();
                    Paciente ViewVacunar = new Paciente();
                    ViewVacunar = hospital.Pacientes.Find(Convert.ToString(Templlave.CodigoHash));
                    ViewVacunacion.Add(ViewVacunar);
                }
            }
            return(View(ViewVacunacion));
        }
Пример #16
0
        /// <summary>
        /// Первый массив на проверку, второй где откуда проверять
        /// </summary>
        /// <param name="Ar"></param>
        /// <param name="Ar2"></param>
        public void Ex6(string[] Ar, string[] Ar2)
        {
            if (Ar.Length > Ar2.Length)
            {
                Console.WriteLine("В списке на проверку больше элементов, чем необходимо");
                return;
            }
            DoubleLinkedList <string> linkedList2 = new DoubleLinkedList <string>();
            DoubleLinkedList <string> linkedList1 = new DoubleLinkedList <string>();

            foreach (string k in Ar2)
            {
                linkedList2.Add(k);
            }
            foreach (string k in Ar)
            {
                linkedList1.Add(k);
                if (!linkedList2.Contains(k))
                {
                    Console.WriteLine("Первый лист содержит элементы которых нет во втором списке");
                    return;
                }
            }
            Console.WriteLine("Все элементы первого содержатся во втором");
        }
        public void Put(int key, int value)
        {
            Node n = null;

            if (_cache.ContainsKey(key))
            {
                n = _cache[key];
            }
            if (n is null)
            {
                Node newNode = new Node()
                {
                    Data = value, Key = key
                };
                _list.Add(newNode);
                _cache.Add(key, newNode);
                _size++;
                if (_size > _capacity)
                {
                    Node deleted = _list.PopTail();
                    _cache.Remove(deleted.Key);
                    _size--;
                }
            }
            else
            {
                _cache[key].Data = value;
                _list.MoveToHead(n);
            }
        }
Пример #18
0
        public void Sort(string commaSeperatedString)
        {
            List <int> elements = commaSeperatedString.Split(',').Select(x => int.Parse(x)).ToList();

            _sorterList = new DoubleLinkedList();

            foreach (var element in elements)
            {
                if (_sorterList.Head == null)
                {
                    _sorterList.Add(element);
                }
                else
                {
                    Node node = _sorterList.Head;
                    while (node.Next != null && (int)node.Value < element)
                    {
                        node = node.Next;
                    }

                    if ((int)node.Value < element)
                    {
                        _sorterList.InsertAfter(node.Value, element);
                    }
                    else
                    {
                        _sorterList.InsertBefore(node.Value, element);
                    }
                }
            }
        }
 // Testing the Add method.
 private void AddNumbers(DoubleLinkedList <int> list)
 {
     for (int i = 1; i < 10; i++)
     {
         list.Add(i);
     }
 }
Пример #20
0
        private static DoubleLinkedList <Student> InitStudents()
        {
            var list = new DoubleLinkedList <Student>();

            list.AddFirst(new Student("AA", 1, false));
            list.AddFirst(new Student("AE", 2, false));
            list.AddFirst(new Student("AI", 5, false));
            list.AddFirst(new Student("AH", 4, true));
            list.AddFirst(new Student("AF", 3, true));
            list.Add(new Student("AG", 4, false));
            list.Add(new Student("AB", 1, true));
            list.Add(new Student("AD", 2, true));
            list.Add(new Student("AJ", 5, true));
            list.Add(new Student("AC", 2, false));
            return(list);
        }
Пример #21
0
        public void DLL_ADD()
        {
            DoubleLinkedList <int> list = new DoubleLinkedList <int>();

            list.Add(1);
            Assert.AreEqual("1", list.ToString());
        }
        public IActionResult ProjectManager()
        {
            for (int i = 1; i <= 10; i++)
            {
                for (int f = 1; f <= F.Tareas.Count2(); f++)
                {
                    var TempListaDev = new DoubleLinkedList <Developer>();
                    TempListaDev = F.Tareas.Clone() as DoubleLinkedList <Developer>;

                    var Temp = new Developer();
                    Temp = TempListaDev.GetbyIndex(f);
                    var Temp2 = new ArbolDePrioridad <LlaveArbolPrioridad>(LlaveArbolPrioridad.Compare_Llave_Arbol);
                    if (!Temp.Tarea.isempty())
                    {
                        Temp2 = Temp.Tarea.Clone();
                        while (!Temp2.isempty())
                        {
                            var Temp3 = new LlaveArbolPrioridad();
                            Temp3 = Temp2.Remove();
                            var Temp4 = new Tarea();
                            Temp4 = F.Tabla_Hash.Remove2(Temp3.CodigoHash, Temp3.CodigoHash);
                            if (Temp4.Prioridad == i)
                            {
                                Viewlista.Add(Temp4);
                            }
                        }
                    }
                }
            }


            return(View(Viewlista));
        }
        public IActionResult ListaVacunados()
        {
            PacienteComp Comparador = Hospitales.Compare_Municipio;
            Hospitales   hospital   = new Hospitales();

            hospital = F.hospitales.Find(m => Comparador(m, HttpContext.Session.GetString("municipio")) == 0);
            var TempViewPaciente = new DoubleLinkedList <Paciente>();

            var Temparbol = new ArbolDePrioridad <LlaveArbolPrioridad>(LlaveArbolPrioridad.Compare_Llave_Arbol);

            if (!hospital.vacunados.isempty())
            {
                Temparbol = hospital.vacunados.Clone();
                while (!Temparbol.isempty())
                {
                    var Templlave = new LlaveArbolPrioridad();
                    Templlave = Temparbol.Remove();
                    var Temppaciente = new Paciente();
                    Temppaciente = hospital.PacientesVacunados.Find(Convert.ToString(Templlave.CodigoHash));
                    TempViewPaciente.Add(Temppaciente);
                }
            }


            return(View(TempViewPaciente));
        }
Пример #24
0
        public void AddValue_WhenValuePassed_AddValueToEnd(int value, int[] actualArray, int[] expectedArray)
        {
            DoubleLinkedList actual   = DoubleLinkedList.Create(actualArray);
            DoubleLinkedList expected = DoubleLinkedList.Create(expectedArray);

            actual.Add(value);
            Assert.AreEqual(expected, actual);
        }
        public void Add_ToAnEmptyListAddsAtTheBegining()
        {
            DoubleLinkedList <string> list = new DoubleLinkedList <string>();

            list.Add("india");

            Assert.AreEqual("india", list[0]);
        }
Пример #26
0
        public void Add_intValue_ShouldAddValue(int a, int[] actualArray, int[] expectedArray)
        {
            DoubleLinkedList expected = new DoubleLinkedList(expectedArray);
            DoubleLinkedList actual   = new DoubleLinkedList(actualArray);

            actual.Add(a);
            Assert.AreEqual(expected, actual);
        }
Пример #27
0
        private DoubleLinkedList <int> CreateDLLOne()
        {
            DoubleLinkedList <int> dll = new DoubleLinkedList <int>();

            dll.Add(24);

            return(dll);
        }
        public void add_value_must_be_in_correct_order_using_previous()
        {
            // assemble
            var list = new DoubleLinkedList<int>();

            // act
            list.Add(5);
            list.Add(15);
            list.Add(45);

            var node = list.Last;

            // assert
            Assert.AreEqual(45, node.Value);
            Assert.AreEqual(15, node.Previous.Value);
            Assert.AreEqual(5, node.Previous.Previous.Value);
        }
Пример #29
0
        public void DLL_REMOVEONE()
        {
            DoubleLinkedList <int> list = new DoubleLinkedList <int>();

            list.Add(1);
            list.Remove();
            Assert.AreEqual("", list.ToString());
        }
Пример #30
0
        private DoubleLinkedList <int> CreateDLLTen()
        {
            DoubleLinkedList <int> dll = new DoubleLinkedList <int>();

            dll.Add(24);
            dll.Add(3);
            dll.Add(6);
            dll.Add(0);
            dll.Add(6);
            dll.Add(17);
            dll.Add(100);
            dll.Add(2014);
            dll.Add(122778);
            dll.Add(42);

            return(dll);
        }
        public void TestAdd(int[] values, int[] expectedArray, int[] actualArray)
        {
            DoubleLinkedList expected = new DoubleLinkedList(expectedArray);
            DoubleLinkedList actual   = new DoubleLinkedList(actualArray);

            actual.Add(values);
            Assert.AreEqual(expected.ToString(), actual.ToString());
        }
Пример #32
0
        public void AddArrayTests(int[] array, int[] expectedArray, int[] addArray)
        {
            DoubleLinkedList expected = new DoubleLinkedList(expectedArray);
            DoubleLinkedList actual   = new DoubleLinkedList(array);

            actual.Add(addArray);
            Assert.AreEqual(expected, actual);
        }
Пример #33
0
        public void AddTest(int[] array, int value, int[] expArray)
        {
            DoubleLinkedList expected = new DoubleLinkedList(expArray);
            DoubleLinkedList actual   = new DoubleLinkedList(array);

            actual.Add(value);
            Assert.AreEqual(expected, actual);
        }
        public void iterate_through_entire_list_and_yield_results()
        {
            // assemble
            var list = new DoubleLinkedList<int>();

            // act
            list.Add(5);
            list.Add(10);
            list.Add(15);

            var result = "";

            foreach (var item in list.Traverse())
            {
                result += item.ToString();
            }

            // assert
            Assert.AreEqual("51015", result);
        }
        public void must_add_node_with_correct_value()
        {
            // assemble
            var list = new DoubleLinkedList<int>();

            // act
            list.Add(10);

            // assert
            Assert.AreEqual(10, list.First.Value);
        }
        public void head_and_tail_must_have_correct_values()
        {
            // assemble
            var list = new DoubleLinkedList<int>();

            // act
            list.Add(5);
            list.Add(15);

            // assert
            Assert.AreEqual(5, list.First.Value);
            Assert.AreEqual(15, list.Last.Value);
        }
        public void remove_node_in_middle_of_list_with_multiple_nodes()
        {
            // assemble
            var list = new DoubleLinkedList<int>();

            // act
            list.Add(5);
            list.Add(10);
            list.Add(15);

            // assert
            Assert.AreEqual(true, list.Remove(10));
            Assert.AreEqual(5, list.First.Value);
            Assert.AreEqual(15, list.Last.Value);
            Assert.AreEqual(15, list.First.Next.Value);
            Assert.AreEqual(5, list.Last.Previous.Value);
        }
        public void remove_one_node_in_list_with_only_one_node()
        {
            // assemble
            var list = new DoubleLinkedList<int>();

            // act
            list.Add(5);

            // assert
            Assert.AreEqual(true, list.Remove(5));
            Assert.IsNull(list.First);
            Assert.IsNull(list.Last);
        }