Está en la página 1de 7

TECNOLOGICO NACIONAL DE MEXICO

INSTITUTO TECNOLOGICO DE TIJUANA


DEPARTAMENTO DE SISTEMAS Y COMPTACION
SEMESTRE: Febrero – junio 2021

REPORTE DE PRACTICA
Nombre del Alumno: Alday JR Castro Ricardo
Unidad No. 3 Nombre Un. :
Practica # 2 Fecha:
27/03/21
Nombre de la Practica: Pilas estáticas usando métodos

PROGRAMA FUENTE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//Alday JR Castro Ricardo 19210458
//Estructura de datos
//Pilas estaticas usando metodos
namespace U3_Problema_2_PilasE_UM
{
class Program
{
static void Main(string[] args)
{
int Tamaño = 50;
string Elemento;
int Top = 0;
string Otro = " ";
string Temporal = " ";

int Menu = 1;
Console.WriteLine("Pila - Ingresar - Eliminar");
Console.WriteLine(" ");
Console.WriteLine(" ");
string[] Pila = new string[50];

Console.Clear();
do
{
Console.WriteLine("Pila - Ingresar y Eliminar");
Console.WriteLine("");
Console.WriteLine("Pila de tamaño [" + Tamaño + "]");
string Eleccion;
Console.WriteLine("");
Console.WriteLine("[1] Ingresar elementos de la pila");
Console.WriteLine("[2] Eliminar elementos de la pila ");
Console.WriteLine("[3] Mostrar la pila ");
Console.WriteLine("[4] BUscar elementos ingresados en la pila");
Console.WriteLine("[?] Para salir del programa");
Console.WriteLine("");
Console.WriteLine("Elige una opcion");
Eleccion = Console.ReadLine();
Console.Clear();
switch (Eleccion)

ESTRUCTURA DE DATOS | MC CLAUDIA NEGRETE SANCHEZ


TECNOLOGICO NACIONAL DE MEXICO
INSTITUTO TECNOLOGICO DE TIJUANA
DEPARTAMENTO DE SISTEMAS Y COMPTACION
SEMESTRE: Febrero – junio 2021
{
case "1":
{
Console.WriteLine("Pila - Ingresar Y Eliminar");
Console.WriteLine("");
Console.WriteLine("Pila de tamaño [" + Tamaño + "]");
Console.WriteLine("");
do
{
Console.WriteLine("Ingresa elemento [" + (Top + 1)
+ "]");
Elemento = Console.ReadLine();
Console.WriteLine(" ");
Top = Insertar(Pila, Tamaño, Top, Elemento);
Console.WriteLine("Quieres ingresar otro pasi? <
[1]si o [?]no >");
Otro = Console.ReadLine();
Console.WriteLine(" ");
}
while (Otro.Equals("1"));
Console.Clear();
}
break;

case "2":
{
Console.WriteLine(" Pila-Ingresar-Eliminar");
Console.WriteLine(" ");
Console.WriteLine(" ");
do
{
Top = Eliminar(Pila, Top, Temporal);
}
while (Otro.Equals("1"));
Console.Clear();
}
break;
case "3":
{
Console.WriteLine("Pila Ingresar Y Eliminar");
Console.WriteLine("");
Console.WriteLine("Pila del tamaño [" + Tamaño + "]");
Console.WriteLine("");

Imprimir(Pila, Top);
Console.WriteLine(" ");
Console.WriteLine(" ");
Console.WriteLine(" pulse una tecla para salir");
Console.ReadKey();
Console.Clear();

}
break;
case "4":
{
string busca;

ESTRUCTURA DE DATOS | MC CLAUDIA NEGRETE SANCHEZ


TECNOLOGICO NACIONAL DE MEXICO
INSTITUTO TECNOLOGICO DE TIJUANA
DEPARTAMENTO DE SISTEMAS Y COMPTACION
SEMESTRE: Febrero – junio 2021
Console.WriteLine(" Pila-Ingresar-Eliminar");
Console.WriteLine(" ");
Console.WriteLine("Pila de tamaño [" + Tamaño + "]");
Console.WriteLine("");
do
{
Console.WriteLine("Quieres buscar un dato en la
pila? < [1]si o [?]no>");
Otro = Console.ReadLine();
Console.WriteLine(" ");
if (Otro.Equals("1"))
{
Console.WriteLine("Escribe el pais a
buscar :");
busca = Console.ReadLine();
Buscar(Pila, Top, busca);

}
} while (Otro.Equals("1"));

Console.Clear();
}
break;
default:
{
Menu = 0;
}
break;
}

}
while (Menu != 0);
}
public static int Insertar(string[] Pila, int Tamaño, int Top, string
Elemento)
{
if (Llena(Top, Tamaño) == true)
{
Console.WriteLine("Pila llena");
Console.WriteLine("Overflow");
Console.WriteLine("");
}
else
{
Pila[Top] = Elemento;
Top = Top + 1;
}
return Top;
}
public static bool Llena(int Top, int Tamaño)
{
if (Top == Tamaño)
return true;
else
return false;
}

ESTRUCTURA DE DATOS | MC CLAUDIA NEGRETE SANCHEZ


TECNOLOGICO NACIONAL DE MEXICO
INSTITUTO TECNOLOGICO DE TIJUANA
DEPARTAMENTO DE SISTEMAS Y COMPTACION
SEMESTRE: Febrero – junio 2021
public static void Buscar(string[] Pila, int Top, string busca)
{
int x = 0; int bandera = 0;
while (x < Top)
{
if (busca.Equals(Pila[x]))
{
Console.WriteLine("Encontrado en posicion {0}", (x + 1));
bandera = 1;
Console.ReadKey();
}
else if (bandera == 0)
{
Console.WriteLine("No se encuentra el valor buscado posicion
{0} ", (x + 1));
}
x++;
}
}
public static int Eliminar(string[] Pila, int Top, string Temporal)
{
if (Vacia(Top) == true)
{
Console.WriteLine("Pila vacia");
Console.WriteLine(" ");
}
else
{
Temporal = Pila[Top - 1];
Console.WriteLine($"Valor eliminado {Temporal}");
Pila[Top - 1] = null;
Top = Top - 1;
}
return Top;
}
public static bool Vacia(int Top)
{
if (Top == -1)
{
return true;
}
else
{
return false;
}
}
public static void Imprimir(string[] Pila, int Top)
{
int cont = 0;
int mayor = 0;
string mayorpil = " ";
string menorpil = " ";
//Ver cual ciudad es mayor de acuerdo a A y a Z
for (int iy = Top - 1; iy >= 0; iy--)
{

ESTRUCTURA DE DATOS | MC CLAUDIA NEGRETE SANCHEZ


TECNOLOGICO NACIONAL DE MEXICO
INSTITUTO TECNOLOGICO DE TIJUANA
DEPARTAMENTO DE SISTEMAS Y COMPTACION
SEMESTRE: Febrero – junio 2021
string cadena = Pila[iy];

char letr = cadena[0];

int a = 0, b = 1, c = 2, d = 3, e = 4, f = 5, g = 6, h = 7, i = 8,
j = 9, k = 10, l = 11, m = 12, n = 13, ñ = 14, o = 15, p = 16, q = 17, r = 18, s =
19, t = 20, u = 21, v = 22, w = 23, x = 24, y = 25, z = 26;
int A = 0, B = 1, C = 2, D = 3, E = 4, F = 5, G = 6, H = 7, I = 8,
J = 9, K = 10, L = 11, M = 12, N = 13, Ñ = 14, O = 15, P = 16, Q = 17, R = 18, S =
19, T = 20, U = 21, V = 22, W = 23, X = 24, Y = 25, Z = 26;
if (letr >= mayor)
{
mayor = letr;
mayorpil = Pila[iy];

}
else if (letr < mayor)
{
menorpil = Pila[iy];

}
if (cont >= 1)
{
Console.WriteLine("\n{0} es menor que {1}", menorpil,
mayorpil);
}

cont = cont + 1;
}
Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine("El pais mayor es {0} " + mayorpil);
Console.WriteLine(" ");
//Imprimir ciudades capturadas
for (int i = Top - 1; i >= 0; i--)
{
Console.WriteLine(Pila[i] + "|");
}
Console.ReadKey();
}
}
}

PANTALLA DE CAPTURA DE DATOS

ESTRUCTURA DE DATOS | MC CLAUDIA NEGRETE SANCHEZ


TECNOLOGICO NACIONAL DE MEXICO
INSTITUTO TECNOLOGICO DE TIJUANA
DEPARTAMENTO DE SISTEMAS Y COMPTACION
SEMESTRE: Febrero – junio 2021

PANTALLA DE RESULTADOS:

ESTRUCTURA DE DATOS | MC CLAUDIA NEGRETE SANCHEZ


TECNOLOGICO NACIONAL DE MEXICO
INSTITUTO TECNOLOGICO DE TIJUANA
DEPARTAMENTO DE SISTEMAS Y COMPTACION
SEMESTRE: Febrero – junio 2021

Retroalimentación

Instrucciones:

Contesta la siguiente pregunta de acuerdo a lo realizado en la práctica.

Que te pareció la práctica, que se te dificulto y como lo solucionaste.

Fue mucho código el que tuve que escribir y me llegue a confundir una que otra vez al momento
de estarlo elaborando pero nada que no se pueda hacer

ESTRUCTURA DE DATOS | MC CLAUDIA NEGRETE SANCHEZ

También podría gustarte