You are on page 1of 3

using System;

using System.Drawing;
using System.Windows.Forms;
using System.IO;
using System.Threading;

class Caja:Form {
private Pila pila_caja;

public Caja() {
this.pila_caja= new Pila();
this.Paint += new PaintEventHandler(Pintar);
}

private void Pintar(object sender, PaintEventArgs e) {


string linea= "";
string[] aEvento;
StreamReader archivo= File.OpenText("eventos_caja.txt");
elemento_de_pila leyendo_libro;
int prioridad= 0;

while (archivo.Peek()>0) {
linea= archivo.ReadLine();
aEvento= linea.Split(',');
e.Graphics.Clear(Color.White);
e.Graphics.DrawString("Evento: "+linea,
new Font("Arial",10),
new SolidBrush(Color.Black),
0,
0);
switch (aEvento[0].ToUpper()) {
case "NUEVO_LIBRO":
this.pila_caja.Push(new elemento_de_pila(aEvento[1], ++prioridad));
break;
case "LEYENDO_LIBRO":
leyendo_libro= this.pila_caja.Pop();
break;
}
this.pila_caja.Pintar(e.Graphics);
Thread.Sleep(2000);
}
e.Graphics.Clear(Color.Black);
}

public static void Main() {


Application.Run(new Caja());
}
}
using System;
using System.Drawing;

class Pila {
private elemento_de_pila[] e= new elemento_de_pila[1000];
private int primero;
private int ultimo;
private int cuantos_elementos;

public Pila() {
this.primero= -1;
this.ultimo= -1;
this.cuantos_elementos= 0;
}

public void Push( elemento_de_pila nuevo_elemento) {


//e[this.ultimo+1]= new elemento_de_pila( nuevo_elemento.GetLibro(), nuevo_elemento.GetNum
e[this.ultimo+1]= nuevo_elemento;
this.ultimo++;
if (this.cuantos_elementos==0)
this.primero= 0;
this.cuantos_elementos++;
}

public elemento_de_pila Pop() {


elemento_de_pila seleccionado= null;

if (this.cuantos_elementos>0) {
seleccionado= e[this.ultimo];
this.ultimo--;
this.cuantos_elementos--;
if (this.cuantos_elementos==0)
this.primero= -1;
}
return(seleccionado);
}

public void Pintar(Graphics area_para_pintar) {


if (this.cuantos_elementos>0) {
for( int i=this.primero; i<= this.ultimo; i++) {
e[i].Pintar( 20, 15*e[i].GetNumeroOrden()+20, area_para_pintar);
}
}
}
}
using System;
using System.Drawing;

class elemento_de_pila {
private string libro;
private int numero_orden;

public elemento_de_pila( string nuevo_libro, int nuevo_numero_orden) {


this.libro= nuevo_libro;
this.numero_orden= nuevo_numero_orden;
}

public void Set( string nuevo_libro, int nuevo_numero_orden) {


this.libro= nuevo_libro;
this.numero_orden= nuevo_numero_orden;
}

public string GetLibro() {


return(this.libro);
}

public int GetNumeroOrden() {


return(this.numero_orden);
}

public void Pintar(int x, int y, Graphics area_para_pintar) {


area_para_pintar.DrawString("("+this.GetNumeroOrden()+") "+this.GetLibro(),
new Font("Arial",10),
new SolidBrush(Color.Blue),
x,
y);
}
}

You might also like