Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Rokas Mikalauskas
- public class MyStaticQueue implements MyQueue {
- //--------------------------------------------------
- // Attributes
- //--------------------------------------------------
- private int items[];
- private int numItems;
- private int maxItems;
- //-------------------------------------------------------------------
- // Basic Operation --> Check if myQueue is empty: myCreateEmpty
- //-------------------------------------------------------------------
- public MyStaticQueue(int m){
- items = new int[m];
- this.numItems = 0;
- this.maxItems = m;
- }
- //-------------------------------------------------------------------
- // Basic Operation --> Check if MyQueue is empty: isEmpty
- //-------------------------------------------------------------------
- public boolean isEmpty(){
- boolean isEmpty = true;
- if(numItems <= 0) {//add this?
- return isEmpty;
- }else {
- isEmpty = false;
- return isEmpty;
- }
- }
- //-------------------------------------------------------------------
- // Basic Operation (Partial) --> Get first element from front of MyQueue: first
- //-------------------------------------------------------------------
- public int first(){
- if(isEmpty()) {
- System.out.println("Its' empty");
- return -1;
- }
- return items[0];
- }
- //-------------------------------------------------------------------
- // Basic Operation (Partial) --> Add element to back of MyQueue: add
- //-------------------------------------------------------------------
- public void add(int element){
- if(numItems < maxItems) {
- items[numItems] = element;
- numItems++;
- }else {
- System.out.println("Can't add, it's full");
- }
- }
- //-------------------------------------------------------------------
- // Basic Operation (Partial) --> Remove element from front of MyQueue: remove
- //-------------------------------------------------------------------
- public void remove(){
- if(numItems > 0) {
- int i = 0;
- for(int x = 0; x < items.length-1; x++) {
- int temp = items[i+1];
- items[i] = temp;
- i++;
- }
- numItems--;
- }else {
- System.out.println("Can't remove, it's empty");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement