The dojox
provides six data structures modules:
Stack
Queue
ArrayList
Dictionary
BinaryTree
SortedList
The dojox.collections.Stack
class implements a LIFO last-in first-out
collection of objects. Here, the element that is inserted last will be removed first.
The dojox.collections.Stack
class implements a FIFO First-in first-out
collection of objects. Here, the element that is inserted first will be removed first.
The dojox.collections.ArrayList
class is a resizable collection of elements. The ArrayList
elements are accessed using an index. This class is similar to a JavaScript array.
The dojox.collections.Dictionary
class is a collection of the key/value
pairs. The key
is used to lookup for the value
.
The dojox.collections.SortedList
class is similar to a dictionary, but the key/value pairs are internally sorted. When a new element is added, the elements of the collection are forced to resort based on the inserted element.
The dojox.collections.BinaryTree
class stores data in a tree structure.
Let's look at the code below:
In the above code
Line 6: We load the dojo
library from the CDN server.
Line 7: We load the dojox.collections.Stack
module
Line 9: We create a new Stack
object with name stack
.
Lines 11 to 13: We use the push method to add three elements to the stack
object.
Line 14: We use the toArray
method to convert stack objects to an array and print the values present in the stack object.
Line 15: We use the count
property to get the number of elements present in the stack.
Line 18: We use the pop
method to remove and get the last inserted element.
Line 23: We use the clear
method to remove all elements of the stack. After calling this method the stack becomes empty.
Note: To understand methods in each data structure, refer here.
Free Resources