When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles
Message Board
Related Web Technologies
User Tips!
Coding Tips

Sample Chapters
Commonly Asked Message Board Questions
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Stump the SQL Guru!
XML Info
Author an Article
ASP ASP.NET ASP FAQs Message Board Feedback
Print this page.
Published: Monday, May 22, 2000

Building a Queue Class using VBScript, Part 2

  • Read Part 1

  • In Part 1 we discussed the rationale behind building a queue class. We discussed what methods and properties would be needed, and looked at how the entire design process could be simplified by reusing the WeakList class presented in the stack class article. In this part, we'll look at the code for the queue class's three methods and single property as well as how to use the queue class in an ASP page!

    - continued -

    <!--#include file="WeakList.Class.asp"-->
    Class Queue
      '... The member variable and event handler sections
           have been omitted for brevity ...
      '************ PROPERTIES *************
      Public Property Get Count()
        Count = wlList.Count
      End Property
      '************* METHODS ***************
      Public Function Enqueue(varItem)
      End Function
      Public Function Dequeue()
        Dequeue = wlList.RemoveTail()
      End Function
      Public Function Peek()
         Peek = wlList.PeekTail()
      End Function
    End Class

    The queue class acts like an ordered list. The first element placed on the queue is the first to be removed. Compare this to the functionality of the stack class, where the first element added was the last element to be removed. A queue is referred to as being FIFO (First In, First Out), while a stack is referred to as being LIFO (Last In, First Out). As with the stack class our queue class's methods and properties are each only one line long, thanks to the WeakList class!

    Here, now, is an example of using the Queue class! Note that this example assumes that the queue class is placed within its own file, Queue.Class.asp. (A live demo is available for this example.)

    <% Option Explicit %>
    <!--#include file="Queue.Class.asp"-->
      Dim objQueue
      Set objQueue = new Queue
      'Push some data on the stack
      objQueue.Enqueue("This ")
      objQueue.Enqueue("is ")
      objQueue.Enqueue("a ")
      objQueue.Enqueue("test! ")
      'What is on the top?
      Response.Write objQueue.Peek() & " is at the head of the queue.<P>"
      'Remove all the data displaying it
      Response.Write "<B>Outputting the queue contents:</B><BR>"
      While objQueue.Count > 0
        Response.Write objQueue.Dequeue() & "<BR>"
      set objQueue = nothing

    In the above example a queue instance is created and four words in a sentence are enqueued. The head of the queue is peeked at, and then the entire queue is dequeued and outputted. Note that the output of the four words would be the exact same order that they were inputed: "This is a test!" This is the nature of a queue, or any FIFO data structure.

    I hope this article has proved useful. Feel free to cut and paste the queue class into your ASP applications. In a future article I plan on tying together all three data structures that we've examined so far and look at several real-world applications in which these data structures are invaluable.

    Until then, happy programming!


  • Download the source to the queue class
  • Download the source to the WeakList class
  • Try out the Queue class demo!

  • ASP.NET [1.x] [2.0] | ASPFAQs.com | Advertise | Feedback | Author an Article