cforster / theme-park-project

An assignment about theme park queues
0 stars 11 forks source link

Question about making the Queues in the Queue class #14

Closed ofreiberg closed 10 years ago

ofreiberg commented 10 years ago

public void put(T t) { if((back+1)%q.length==front%q.length) resize(); q[back++%q.length]=t; }

how does this line work/what exactly does this line do? lines 13-16

cforster commented 10 years ago

Here's an English description:

put an item called t of type T in the queue: if the array is full, resize it (ie if front is about to be back) then put the the item t at the back of the array.

the %q.length is used everywhere to make sure we always go around the edge of the array.