Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Delita

Mostrar resultado/criar fila no HTML

Recommended Posts

Olá,

 

Estou querendo usar um script para criação de filas e mostrar resultado(ou criar as filas) no html só que não estou conseguindo fazer este último.

 

Aqui está o script.js:

 

function Queue(){

 // initialise the queue and offset
 var queue  = [];
 var offset = 0;

 /* Returns the length of the queue.
  */
 this.getLength = function(){

   // return the length of the queue
   return (queue.length - offset);

 }

 /* Returns true if the queue is empty, and false otherwise.
  */
 this.isEmpty = function(){

   // return whether the queue is empty
   return (queue.length == 0);

 }

 /* Enqueues the specified item. The parameter is:
  *
  * item - the item to enqueue
  */
 this.enqueue = function(item){

   // enqueue the item
   queue.push(item);

 }

 /* Dequeues an item and returns it. If the queue is empty then undefined is
  * returned.
  */
 this.dequeue = function(){

   // if the queue is empty, return undefined
   if (queue.length == 0) return undefined;

   // store the item at the front of the queue
   var item = queue[offset];

   // increment the offset and remove the free space if necessary
   if (++ offset * 2 >= queue.length){
     queue  = queue.slice(offset);
     offset = 0;
   }

   // return the dequeued item
   return item;

 }

 /* Returns the item at the front of the queue (without dequeuing it). If the
  * queue is empty then undefined is returned.
  */
 this.peek = function(){

   // return the item at the front of the queue
   return (queue.length > 0 ? queue[offset] : undefined);

 }

}

 

E o que tentei fazer:

 

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>teste fila</title>
<script type = "text/javascript" src = "Queue.js"></script>
<script>
var queue = new Queue();

queue.enqueue('animal');
queue.enqueue('moron');
queue.peek();

document.writeln(queue);
</script>

</head>

<body>
</body>
</html>

 

Mas não mostra os resultados.

 

 

Como eu trabalho com este script no html? por exemplo chamar algumas filas e mostrar elas.

 

Obrigado!

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.