For faster navigation, this Iframe is preloading the Wikiwand page for Pila acotada.

Pila acotada

Este artículo o sección necesita referencias que aparezcan en una publicación acreditada. Busca fuentes: «Pila acotada»noticias · libros · académico · imágenesEste aviso fue puesto el 16 de abril de 2011.

Una pila acotada es una estructura de datos de tipo LIFO (el último elemento en entrar, es el primero en salir) cuyo tamaño máximo queda limitado en su especificación.

Operaciones

[editar]

Una pila acotada cuenta con operaciones básicas:

  • Crear: se crea la pila vacía.
  • Apilar: se añade un elemento a la pila.(push)
  • Desapilar: se elimina el elemento frontal de la pila.(pop)
  • Cima: devuelve el elemento que está en la cima de la pila. (top o peek)
  • Vacía: devuelve cierto si la pila está vacía o falso en caso contrario.
  • Llena: devuelve cierto si la pila está llena o falso en caso contrario.

Lógicamente no podremos apilar en una pila que está llena.

Implementación

[editar]

Para ilustrar exponemos la implementación de una pila acotada.

En MAUDE

[editar]

Necesitaremos una teoría para definir el tama o máximo de la pila.

fth CONSTANTE is
  protecting NAT .
  op cte: -> NAT .
endfth

Pasamos a definir la pila acotada parametrizada.

fmod PILA-ACOTADA {X :: TRIV , AC :: CONSTANTE} is
  protecting NAT .
  sorts PilaAC{X , AC} PilaACNV{X , AC} .
  subsort PilaACNV{X , AC} < PilaAC{X , AC} .
  *** generadores
  op crear : -> PilaAC{X , AC} [ctor] .
  op apilar : X$Elt PilaAC{X , AC} -> PilaACNV{X , AC} [ctor] .
  *** constructores
  op desapilar : PilaAC{X , AC} -> PilaAC{X , AC} .
  *** selectores
  op cima : PilaACNV{X , AC} -> X$Elt .
  op longitud : PilaAC{X , AC} -> Nat .
  op estaLlena? : PilaAC{X , AC} -> Bool .
  *** variables
  var P : PilaAC{X , AC} .
  var E : X$Elt .
  *** ecuaciones impurificadoras
  ceq apilar (E, P) = P if estaLlena?(P) .
  eq desapilar (crear) = crear .
  ceq desapilar (apilar(E, P)) = P if not estaLlena?(P) .
  ceq cima (apilar(E, P)) = E if not estaLlena?(P) .
  eq longitud (crear) = 0 .                    
  ceq longitud (apilar(E, P)) = 1 + longitud (P)
     if not estaLlena?(P) .                      
  eq estaLlena?(P) = longitud (P) >= cte .
endfm

Véase también

[editar]
{{bottomLinkPreText}} {{bottomLinkText}}
Pila acotada
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?