# Thread: Stack and Queue "quack" circular array

1. Daved,
thank you for all your help! I do have updated code.
I know i still need to check if full, but i will worry about that later.

I did try what you suggested: back started at 6 and front started at 7.
However, i couldnt get it in the right order

This is what i have.

Code:
```quack::quack(int capacity)
{

items = new item[capacity];

items->n = 0;
count = 0;
back = capacity;
front = capacity-1;
maxsize = capacity;

}```
Code:
```bool quack::pushFront(const int n)
{

if ( count == maxsize )
{

return false;
}
front = (front - 1) % maxsize;
items[front].n = n;
count++;

return true;

}```
Code:
```bool quack::pushBack(const int n)
{
back = (back - 1) % maxsize;
items[back].n = n;
count++;

return true;

}```
If you look at the for loop to get it to display properly i had to
start at 1 and add 1 to count. Now, that may go back to what you were suggestion before. However, it didnt work.

Code:
```ostream& operator<<(ostream& out, quack& q)
{

if ( q.count == 0 ) // no elements have been counted.
out << endl << "quack: empty" << endl;
else
{
out << endl << "quack: ";
for ( int i = 1; i < q.count + 1; i++ )
{

out << q.items[i].n << ", ";

}
out << endl << endl;
}
return out;```

output is what i suppse to have

Code:
```CS260 - Lab2 - Your Name

quack: empty
>>> pushFront 1 succeeded
>>> pushFront 2 succeeded
>>> pushFront 3 succeeded
>>> pushFront 4 succeeded
>>> pushBack 0 succeeded
>>> pushFront 9 succeeded

quack: 9, 4, 3, 2, 1, 0,

--- # of items: 6

>>> popFront failed

quack: 9, 4, 3, 2, 1, 0,

>>> popFront failed

quack: 9, 4, 3, 2, 1, 0,

>>> pushBack 7 succeeded

quack: 9, 4, 3, 2, 7, 0, -33686019,

>>> pushBack 8 succeeded```