function Deque()
{
this.stac=new Array();
this.popback=function(){
return this.stac.pop();
}
this.pushback=function(item){
this.stac.push(item);
}
this.popfront=function(){
return this.stac.shift();
}
this.pushfront=function(item){
this.stac.unshift(item);
}
}
//push is function of Array in javascript to enter variable in last index of array.
//pop is function of Array in javascript to remove last variable from array.
//shift is use to add element in start of the array .
//unshift is use to remove element from start of the array .
function implementation {
var deque=new Deque();
deque.pushfront("Prashant");
deque.pushfront("Gaur");
deque.pushback("Deepak");
alert(deque.popfront());alert(deque.popback());
alert(deque.popback());
alert(deque.popback());
}
You can design function for Queue also only by using pop and unshift . :)
Thanks & Regards :
Prashant Gaur
+91 9030015491
91prashantgaur@gmail.com
No comments:
Post a Comment