示例#1
0
        public static void AdicionarNodoPosicionLista(Huesped pHuesped, int pos)
        {
            Huesped tem  = cabecera;
            int     cont = 0;

            pos--;

            if (cabecera == null)
            {
                throw new Exception("El valor de pos = " + (pos + 1) + ", es mayor que el tamaño de la lista " + Environment.NewLine + "El estudiante no puede ser agregado" + Environment.NewLine + "Revise la lista y la posición que quiere agregar e intente de nuevo");
            }

            if (pos == 0)
            {
                pHuesped.SetSiguiente(cabecera);
                cabecera = pHuesped;
                return;
            }

            while (tem != null)
            {
                if (cont == pos)
                {
                    break;
                }

                tem = tem.GetSiguiente();
                cont++;
            }

            if (cont < pos || tem == null)
            {
                throw new Exception("El valor de pos = " + (pos + 1) + ", es mayor al tamaño de la lista! " + Environment.NewLine + "Estudiante NO adicionado!");
            }

            // pHuespedes.SetSiguiente(tem.GetSiguiente());

            // tem.SetSiguiente(pHuespedes);
            //<1><1><1><1>
            tem.GetAnterior().SetSiguiente(pHuesped);
            pHuesped.SetAnterior(tem.GetAnterior());
            pHuesped.SetSiguiente(tem);
            tem.SetAnterior(pHuesped);
        }
示例#2
0
        public static void EliminarPocision(int pos)
        {
            pos--;
            Huesped tem  = cabecera;
            int     cont = 0;

            if (pos == 0 && tem.GetSiguiente() == null)
            {
                EliminarInicio();
            }
            else
            {
                while (tem != null)
                {
                    if (cont == pos)
                    {
                        break;
                    }

                    tem = tem.GetSiguiente();
                    cont++;
                }
                if (tem.GetSiguiente() != null && tem.GetAnterior() != null)
                {
                    tem.GetSiguiente().SetAnterior(tem.GetAnterior());
                    tem.GetAnterior().SetSiguiente(tem.GetSiguiente());
                }
                else if (tem.GetSiguiente() == null)
                {
                    EliminarFinal();
                }
                else if (tem.GetAnterior() == null)
                {
                    EliminarInicio();
                }
            }
        }
示例#3
0
        public static void EliminarFinal()
        {
            Huesped temp = cabecera;

            // 1><1><1>
            if (cabecera.GetSiguiente() == null)
            {
                cabecera = null;
            }
            else
            {
                while (temp.GetSiguiente() != null)
                {
                    temp = temp.GetSiguiente();
                }
                temp.GetAnterior().SetSiguiente(null);
                temp.SetAnterior(null);
            }
        }