C sharp - ayuda lista doble enlazada con nodos

 
Vista:
sin imagen de perfil
Val: 4
Ha aumentado su posición en 7 puestos en C sharp (en relación al último mes)
Gráfica de C sharp

ayuda lista doble enlazada con nodos

Publicado por francisco antonio (4 intervenciones) el 14/11/2018 02:34:09
hola me pueden ayudar a como insertar un dato en un lugar especifico y como recorrer una lista del inicio le paso mi codigo haber si me pueden ayudar


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
namespace listdob
{
    class Lista
    {
        Nodo first, last;
 
        public Lista() { first = last = null; }
 
        public void Ingresar()
        {
            string nom;
            Console.Clear();
            Console.WriteLine("Ingrese Datos ");
            Console.WriteLine("**************");
            Console.Write("Ingrese Numero: ");
            nom = Console.ReadLine();
            Nodo i = new Nodo(nom);
            Insertar(i);
        }
        public void inseresp()
        {
 
        }
        public void Ingresasin()
        {
            string nom;
            Console.Clear();
            Console.WriteLine("Ingrese Datos ");
            Console.WriteLine("**************");
            Console.Write("Ingrese Numero: ");
            nom = Console.ReadLine();
            Nodo z = new Nodo(nom);
            Insertarin(z);
 
        }
        /*public void recorrer()
        {
            Nodo temp = first;
            while (temp != null)
            {
                temp.
                temp = temp.sig;
            }
        }
        */
        public void Mostrar()
        {
            Nodo i;
            if (first != null)
            {
                i = first;
                while (i != null)
                {
                    i.Mostrar();
                    i = i.sig;
                }
            }
            else
            {
                Console.WriteLine("lista vacia");
            }
            Console.ReadLine();
        }
 
        public Nodo Buscar(string b)
        {
            Nodo i;
            i = first;
            while (i != null)
            {
                if (i.NOMBRE == b)
                    return (i);
                else
                    i = i.sig;
            }
            return (null);
        }
 
        public bool Eliminar()
        {
            string busca;
            Nodo padre, hijo;
            Console.Write("Ingrese nombre del empleado a eliminar: ");
            busca = Console.ReadLine();
            padre = Eliminar(busca);
            if (padre == last)
                return (false);
            if (padre == null)
            {
                hijo = first;
                first = hijo.sig;
            }
            else
            {
                hijo = padre.sig;
                padre.sig = hijo.sig;
            }
            if (hijo == last)
            {
                last = padre;
                hijo = null;
 
            }
            return (true);
 
        }
 
        public Nodo Eliminar(string b)
        {
            Nodo i, p;
            i = first;
            p = null;
            while (i != null)
            {
                if (i.NOMBRE == b)
                    break;
                else
                {
                    p = i;
                    i = i.sig;
                }
            }
            return (p);
        }
 
        private void Insertar(Nodo i)
        {
            if (first == null)
            {
                first = i;
                last = i;
            }
 
            else
            {
                last.sig = i;
                last = i;
            }
 
        }
        private void Insertarin(Nodo i)
        {
            if (first == null)
                first = i;
            else
            {
                i.sig = first;
                first = i;
            }
 
        }
        public void inseresp(Nodo i)
        {
            if (first == null)
            {
                first = i;
            }
            else
            {
                Nodo temp = first;
                int cuen=0;
                int pos = 0;
                while (temp != null && cuen != pos)
                {
 
                }
            }
        }
    }
}





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
namespace listdob
{
    class Nodo
    {
        private string Nombre;
 
        public Nodo sig;
        public Nodo(string nombre) { this.Nombre = nombre; this.sig = null; }
 
        public void Mostrar() { Console.WriteLine("Nombre :{0}", this.Nombre); }
 
        public string NOMBRE { get { return (Nombre); } }
 
    }
}



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
namespace listdob
{
    class Program
    {
        static void Main(string[] args)
        {
            short op;
            string busca;
            Nodo v;
            Lista m = new Lista();
            do
            {
                Console.Clear();
                Console.WriteLine("\tLISTAS ENLAZADAS\n");
                Console.WriteLine("1. Ingresar Final");
                Console.WriteLine("2. Mostrar");
                Console.WriteLine("3. Buscar");
                Console.WriteLine("4. Eliminar");
                Console.WriteLine("5. Intercambiar");
                Console.WriteLine("6. Recorrer un dato");
                Console.WriteLine("7. Ingresar inicio ");
                Console.Write("Ingrese opción: ");
                op = Convert.ToInt16(Console.ReadLine());
                switch (op)
                {
                    case 1:
                        m.Ingresar();
                        break;
                    case 2:
                        Console.Clear();
                        m.Mostrar();
                        break;
                    case 3:
                        Console.Clear();
 
                        Console.Write("Ingrese valor a buscar: ");
                        busca = Console.ReadLine();
                        v = m.Buscar(busca);
                        if (v == null)
                            Console.WriteLine("No existe el Empleado");
                        else
                        {
                            Console.WriteLine("Nodo encontrado");
                            v.Mostrar();
                        }
                        Console.ReadLine();
                        break;
                    case 4:
                        if (m.Eliminar())
                            Console.WriteLine("Nodo eliminado...");
                        else
                            Console.WriteLine("Nodo no encontrado...");
                        Console.ReadLine();
                        break;
                    case 5:
                        Console.Clear();
 
                        break;
                    case 6:
                        Console.Clear();
 
                        break;
                    case 7:
                        m.Ingresasin();
                        break;
                    default:
                        Console.WriteLine("Proceso Terminado...");
                        break;
                }
            } while ((op > 0) && (op < 8));
        }
 
    }
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder