Basically, these are two queue classes that take in and out values at the ends of the queue. You can not add anything into the queue between the ends.
Pushing is a resource-intensive operation at the lowest point of the queue, it has to loop through all of the items on the queue in order to do the desired operation.
Popping is a non-resource-intensive operation at the highest point of the queue, it doesn't loop through the items.
Lowest In Highest Out:
Given a LIHO queue with 5 items:
0 << Point where queue SO pushes in an item, and has to loop through the other 4.
1
2
3
4 << Point where queue SO pops out an item.
In order to replicate this set on a LIHO queue, you would have to push in the set {4, 3, 2, 1, 0}.
Highest In Lowest Out:
Given a HILO queue with 5 items:
0 << Point where queue SO pushes out an item, and has to loop through the other 4.
1
2
3
4 << Point where queue SO pops in an item.
In order to replicate this set on a HILO queue, you would have to pop in the set {0, 1, 2, 3, 4}.
Stack Limitations
For both example queues, the middle items {1, 2, 3} can NOT be changed.
Source
//lowest in highest out
function LIHOStackSO::onAdd(%this)
{
%this.size = 0;
}
function LIHOStackSO::pushIn(%this,%val)
{
for(%i=%this.size-1;%i>=0;%i--)
{
%m = %this.element[%i];
%this.element[%i] = "";
%this.element[%i+1] = %m;
}
%this.element[0] = %val;
%this.size++;
}
function LIHOStackSO::popOut(%this)
{
if(%this.size <= 0)
{
%this.size = 0;
return;
}
%e = %this.element[%this.size-1];
%this.element[%this.size-1] = "";
%this.size--;
return %e;
}
//highest in lowest out
function HILOStackSO::onAdd(%this)
{
%this.size = 0;
}
function HILOStackSO::popIn(%this,%val)
{
%this.element[%this.size] = %val;
%this.size++;
}
function HILOStackSO::pushOut(%this)
{
if(%this.size <= 0)
{
%this.size = 0;
return;
}
%e = %this.element[0];
for(%i=0;%i<%this.size;%i++)
{
%m = %this.element[%i];
%this.element[%i] = "";
%this.element[%i-1] = %m;
}
%this.size--;
return %e;
}