Está en la página 1de 8

PROYECTO DE ESTRUCTURA DE DATOS INDICACIONES:

UTILIZANDO LISTAS ENLAZADAS Y ÁRBOLES BINARIOS IMPLEMENTAR UNA APLICACIÓN QUE LE


PERMITA GESTIONAR LAS NOTAS DE LOS ALUMNOS DE UNA INSTITUCIÓN EDUCATIVA. PARA
ESTO DEBE REGISTRAR LOS SIGUIENTES DATOS DE UN ALUMNO:

- Nombre

- Apellido

- Edad

- DNI

- Carrera Profesional

- Lista Cursos

EN LA LISTA DE CURSOS SE ALMACENARÁN TODOS LOS CURSOS DE UN ALUMNO,


CONSIDERANDO EL NOMBRE DEL CURSO Y EL PROMEDIO

NOTA: DEBE CREAR TODAS LAS CLASES Y ESTRUCTURAS NECESARIAS PARA IMPLEMENTAR
ADECUADAMENTE SU APLICACIÓN.

EL PROGRAMA DEBE TENER LA SIGUIENTE ESTRUCTURA


============================MENÚ DE OPCIONES===========================

===== [1] REGISTRAR ESTUDIANTE ORDENADO POR APELLIDO (ÁRBOL BINARIO) ===

===== [2] RECORRER ÁRBOL PREORDER ===

===== [3] RECORRER ÁRBOL INORDER ===

===== [4] RECORRER ÁRBOL POSTORDER ===

===== [5] BUSCAR ALUMNO POR APELLIDO ===

===== [6] CONVERTIR A LISTA ENLAZADA ===

===== [7] RECORRER LISTA DE ALUMNOS ===

===== [8] LISTAR LAS ASIGNATURAS Y NOTAS DE UN ALUMNO ===

===== [9] BUSCAR LOS ALUMNOS DE UNA CARRERA PROFESIONAL ===

===== [10] SALIR ===


========================================================================

Program.cs
namespace proyecto_esdat
{
class Program
{
static void Main(string[] args)
{
string apellido;
ArbolAlumno a = new ArbolAlumno();
int opcion=0;
do
{
Console.Write("\n============================MENÚ DE
OPCIONES===========================");
Console.Write("\n===== [1] REGISTRAR ESTUDIANTE ORDENADO POR
APELLIDO (ÁRBOL BINARIO)===");
Console.Write("\n===== [2] RECORRER ÁRBOL PREORDER
===");
Console.Write("\n===== [3] RECORRER ÁRBOL INORDER
===");
Console.Write("\n===== [4] RECORRER ÁRBOL POSTORDER
===");
Console.Write("\n===== [5] BUSCAR ALUMNO POR APELLIDO
===");
Console.Write("\n===== [6] CONVERTIR A LISTA ENLAZADA
===");
Console.Write("\n===== [7] RECORRER LISTA DE ALUMNOS
===");
Console.Write("\n===== [8] LISTAR LAS ASIGNATURAS Y NOTAS DE UN
ALUMNO ===");
Console.Write("\n===== [9] BUSCAR LOS ALUMNOS DE UNA CARRERA
PROFESIONAL ===");
Console.Write("\n===== [10] SALIR
===");

Console.Write("\n================================================================
=======");
Console.Write("\nEscoja una Opcion: ");
opcion = int.Parse(Console.ReadLine());
switch (opcion)
{
case 1:
Console.Write("\nREGISTRAR EN ORDEN UN ESTUDIANTE EN EL
ÁRBOL.\n\n");
Alumno a1 = new Alumno("Alan","Acosta","sistemas", 19 ,
91670131 );
Alumno a2 = new Alumno("Raul", "Solorzano",
"contabilidad", 20, 91650131);
Alumno a3 = new Alumno("Anderson", "Ventura", "civil",
18, 91670258);
Alumno a4 = new Alumno("Wilson", "Sanchez",
"agroindustrial", 25, 14720131);
Alumno a5 = new Alumno("Cleiner", "Quiñones", "sistemas",
22, 91625831);
Alumno a6 = new Alumno("Osni", "Torres", "sistemas", 19,
91147254);
Alumno a7 = new Alumno("Adin", "Flores", "civil", 20,
74196352);
Alumno a8 = new Alumno("Marco", "Yupanqui", "psicologia",
21, 14725369);

ArbolAlumno af = new ArbolAlumno();


a.insertar(a1);
a.insertar(a2);
a.insertar(a3);
a.insertar(a4);
a.insertar(a5);
a.insertar(a6);
a.insertar(a7);
a.insertar(a8);
break;
case 2:
Console.Write("\nARBOL PREORDEN.\n\n");
a.preOrden(a.raiz);
break;
case 3:
Console.Write("\nARBOL INORDEN.\n\n");
a.inOrden(a.raiz);
break;
case 4:
Console.Write("\nARBOL POSTORDEN.\n\n");
a.postOrden(a.raiz);
break;
case 5:
Console.Write("\n\nBUSCAR ALUMNO EN EL ÁRBOL.\n\n");
Console.Write("APELLIDO: ");
apellido = Console.ReadLine();
bool r = a.buscar(a.raiz, apellido);
if (r)
Console.WriteLine("\n" + apellido + " SI Existe ");
else
Console.WriteLine("\n" + apellido + " NO Existe ");

break;
case 6:

break;
case 7:

break;
case 8:

break;
case 9:

break;
case 10:
Console.Write("\n\nPROGRAMA FINALIZADO.\n\n");
break;
default:
Console.Write("\n\nOPCIÓN INCORRECTA.\n\n");
break;
}
} while (opcion != 10);
}
}
}

NodoA.cs
namespace proyecto_esdat
{
public class NodoA
{
public Alumno Dato;
public NodoA Izquierdo;
public NodoA Derecho;

public NodoA(Alumno alumno)


{
this.Dato = alumno;
this.Izquierdo = null;
this.Derecho = null;
}

}
}

ArbolAlumno.cs

namespace proyecto_esdat
{
class ArbolAlumno
{
public NodoA raiz;

public ArbolAlumno()
{
raiz = null;
}

public void insertar(Alumno alumno)


{
NodoA nuevo = new NodoA(alumno);
if (raiz == null)
raiz = nuevo;
else
{
NodoA aux = raiz;
while (aux != null)
{
if (alumno.apellido.CompareTo(aux.Dato.apellido) < 0)
{
if (aux.Izquierdo != null)
aux = aux.Izquierdo;
else
{
aux.Izquierdo = nuevo;
break;
}
}
else
{
if (aux.Derecho != null)
aux = aux.Derecho;
else
{
aux.Derecho = nuevo;
break;
}
}

}
}

public void preOrden(NodoA r)


{
if (r != null)
{
Console.WriteLine(r.Dato.imprimir());
preOrden(r.Izquierdo);
preOrden(r.Derecho);
}

public void inOrden(NodoA r)


{
if (r != null)
{
inOrden(r.Izquierdo);
Console.WriteLine(r.Dato.imprimir());
inOrden(r.Derecho);
}
}

public void postOrden(NodoA r)


{
if (r != null)
{
postOrden(r.Izquierdo);
postOrden(r.Derecho);
Console.WriteLine(r.Dato.imprimir());
}
}

public bool buscar(NodoA r, string clave)


{
NodoA aux = raiz;
if (aux != null)
{
if (clave.Equals(aux.Dato.apellido))
return true;
else if (clave.CompareTo(aux.Dato.apellido)<0)
{
aux = aux.Izquierdo;
return buscar(r, clave);
}
else
{
aux = aux.Derecho;
return buscar(r, clave);
}
}
else
return false;
}
}
}

Nodo.cs

namespace proyecto_esdat
{
class Nodo
{
public int Dato;
public Nodo Siguiente;
}
}

Alumno.cs

namespace proyecto_esdat
{
public class Alumno
{

public string nombre,apellido,carrera;


public int edad,dni;

public Alumno(string nombre, string apellido,string carrera,int edad,int


dni)
{
this.nombre = nombre;
this.apellido = apellido;
this.carrera = carrera;
this.edad = edad;
this.dni = dni;
}

public string imprimir()


{
return "Nombre: " + nombre + "\tapellido: " + apellido + "\tcarrera:
" + carrera + "\tedad: " + edad + "\tdni: " + dni;
}

}
}

Lista.cs

namespace proyecto_esdat
{
class Lista
{
public Nodo inicio;
public Lista()
{
inicio = new Nodo();
inicio.Siguiente = null;
}

public bool pertenece(int dato)


{
Nodo tmp = inicio.Siguiente;
while (tmp != null)
{
if (tmp.Dato == dato)
return true;
tmp = tmp.Siguiente;
}
return false;
}

public static Lista union(Lista A, Lista B)


{
Lista U = new Lista();
Nodo tmp = A.inicio.Siguiente;
while (tmp != null)
{
if (!U.pertenece(tmp.Dato))
U.insertar(tmp.Dato);

tmp = tmp.Siguiente;
}
tmp = B.inicio.Siguiente;
while (tmp != null)
{
if (!U.pertenece(tmp.Dato))
U.insertar(tmp.Dato);

tmp = tmp.Siguiente;
}

return U;
}

public static Lista interseccion(Lista A, Lista B)


{
Lista I = new Lista();
Nodo tmp = A.inicio.Siguiente;
while (tmp != null)
{
if (B.pertenece(tmp.Dato))
{
I.insertar(tmp.Dato);
}
tmp = tmp.Siguiente;
}
return I;
}

public void insertar(int Dato)


{
Nodo nuevo = new Nodo();
nuevo.Dato = Dato;

nuevo.Siguiente = inicio.Siguiente;
inicio.Siguiente = nuevo;
}

public void mostrar()


{
Nodo tmp = inicio.Siguiente;
while (tmp != null)
{
Console.Write(tmp.Dato + "->");
tmp = tmp.Siguiente;
}
}

public Nodo buscarPar()


{
Nodo tmp = inicio;
while (tmp.Siguiente != null)
{
if (tmp.Siguiente.Dato % 2 == 0)
return tmp;
tmp = tmp.Siguiente;
}
return null;
}

}
}

También podría gustarte