ListQueue
member functions compare with the seven apstack member functions in
the table.
apstack | ListQueue |
push(n) | |
pop(n) | |
isEmpty( ) | |
pop( ) | |
n = top( ) | |
n = length( ) | |
makeEmpty( ) |
ListQueue Q;
Q.enqueue(5);
Q.enqueue(6);
Q.enqueue(7);
Q.enqueue(8);
int x=Q.peekFront( );
int y;
y=Q.dequeue();
Q.enqueue(x);
Q.enqueue(++y);
Q.dequeue();
y=Q.dequeue();
while( !Q.isEmpty( ) )
x=Q.dequeue();
System.out.println(x);
ListQueue Q;
int x = 2;
Q.enqueue(4);
Q.enqueue(x);
Q.enqueue(Q.peekFront( ));
Q.enqueue(3+Q.peekFront( ));
Q.enqueue(0);
Q.dequeue();
while(!Q.isEmpty())
{
x=Q.dequeue();
System.out.print(x);}
System.out.println();
apstack S;
ListQueue Q;
int a=0, b=1;
int c=a+b;
while (c<10)
{
if (c%2==0)
S.push(c);
else Q.enqueue(c);
a=b;
b=c;
c=a+b;
}
while ( !S.isEmpty( ) )
{
S.pop(c);
System.out.print(c);
}
while ( !Q.isEmpty( ) )
{
c=Q.dequeue();
System.out.print(c);
}