I have a question about the data structure queue!

Asked 1 years ago, Updated 1 years ago, 89 views

public static void enQueue(int data){

if(isFull()){
    throw new QueueOverflowException("Queue Overflow");
   }else{
        rear = (rear+1)%capacity;
        array[rear] = data;
        if(front == -1) front = rear;
    }
   }

}

If there is [1, 2, 3, 4, 5] in the array and 1 is the front,

If rear = (rear +1)% capacity is used, it becomes 6%5 = 1, and the rear is reset to 1 I thought about it, but I wonder if queue works like this!

queue

2022-09-22 14:44

1 Answers

I was going to give you an answer.

I don't quite understand what you're sayingㅠ<

Please explain it a little bit


2022-09-22 14:44

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.