1 / 5

PILAS (STACK)

PILAS (STACK).

clover
Download Presentation

PILAS (STACK)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. PILAS (STACK)

  2. Una pila (stack en inglés) es una estructura de datos de tipo LIFO (del inglés Last In First Out, último en entrar, primero en salir) que permite almacenar y recuperar datos. Se aplica en multitud de ocasiones en informática debido a su simplicidad y ordenación implícita en la propia estructura.

  3. Ejemplo en C# static void Main(string[] args) { int max; Console.WriteLine("Cantidad:"); max = Convert.ToInt32(Console.ReadLine()); Stack<int> pila = new Stack<int>(max); Console.Title = "Ejemplo con PILAS"; //El metodo .Title le pone un titulo a la ocnsola Console.ForegroundColor = ConsoleColor.Green; // Le pone un color al tetxo Console.BackgroundColor = ConsoleColor.White; //Le asigna un color de fondo al texto // la instruccion Stack esta declarando que es una estructura de tipo pila que recibira datos de tipo entrero y se llama pila for (int i=1; i<=max; i++) { Console.WriteLine("Elemento {0}:", i); pila.Push(Convert.ToInt32(Console.ReadLine())); //El metodo push indica que se ingresaran valores a la pila }

  4. Console.WriteLine(""); Console.WriteLine("El elemento mayor de la pila es:" + pila.Max()); //El metodo .Max muestra elelemento de la pila que es mayor Console.WriteLine("El elemento menor de la pila es:" + pila.Min()); //El metodo .Min muestra elelemento de la pila que es mayor Console.WriteLine(""); Console.BackgroundColor = ConsoleColor.Blue; Console.WriteLine("Impresión:"); for (int i=1; i<=max; i++) { Console.WriteLine(pila.Pop()); // el metodo Pop indica que se mostraran los valores que contiene la pila } Console.ReadLine(); }

  5. Representación gráfica de una pila

More Related