Home > Back-end >  2020-11-14: write code: how to use the array size does not exceed the fixation of the queue?
2020-11-14: write code: how to use the array size does not exceed the fixation of the queue?

Time:11-15

2020-11-14: write code: how to use the array size does not exceed the fixation of the queue? # # f greatly architects a daily topic

CodePudding user response:

 
Public class LimitQueue {
Private int [] array;
Private int size;
private int index;

Public LimitQueue (int size) {
Array=new int [size];
This. Size=size;
Enclosing the index=1;
}

Public void push (int value) {
If (index & lt; The size 1) {
Index++;
Array [index]=value;
} else {
System. The out. Println (" array is full ");
}
}

Public int the pop () {
If (index & gt;=0) {
The int value=https://bbs.csdn.net/topics/array [index];
The index -;
System. The out. Println (" array pop-up element: "+ value);
return value;
} else {
System. The out. Println (" array can pop-up element ");
return 0;
}
}

}
  • Related