problem in understanding stacks and queues

Hi all.
i'm preparing the c++ test and i got some problems with stacks and queues.
i have not clear how the push/pop functions have to be organized, and their implementation in a for cycle. I try to be more clear.
The only examples of those functions that i have are from the corrections of the old tests of my teacher: i tried to analyze them in order to understand better but nothing. Example:
1
2
3
4
5
6
7
8
9
const int MAXNUM = 20
[...]

int posizione(const char c[], const char n[], const CodaRichieste* cr) {
  for(int i=cr->front; i != cr->back; i = (i+1)%MAX)
    if(strcmp(n, cr->ric[i].nome) == 0 && strcmp(c, cr->ric[i].cognome) == 0) 
      return (i + MAX - cr->front) % MAX;
  return 0;
}

what does it means the %MAX that appears sometimes? I found it in a lot of test's solutions but i cant't arrive to an explanation.and also: why the for cycle have to stop when i != back ? (MAX is the maximum size of an array).

Have a nice day!
by looking at the traversal, i can say its a circular queue, google circular queue to understand why % max is being done, i dont know what comparison is being performed though.
Topic archived. No new replies allowed.