In the context of the queue data structure, the increment and decrement of array size work in the following way: Decrease factor:- It decides when the size of the array should be decreased.Increase Factor:- Multiplication factor by which the array size is increased, for example, increase factor 2 means the size of the array is double every time it gets too full.Initial capacity:- Size of the array during its creation.For this first create the following three variables, these variables will help us to decide when the size of the array should be increased and when it should be decreased. ![]() We have to implement a dynamic array using an array object provided in java language. Queue.isEmpty() // returns false SolutionÄynamic array is an array whose size automatically increased when it gets too full and, its size gets decreased when it is too empty. iterator() :- It returns the java iterator object for iterating through the elements of the queue.size() :- It return the total number of elements.isEmpty() :- It checks whether the queue is empty.peek() :- It returns (not remove) the element from the front of the queue.dequeue() :- It removes and returns the element from the front of the queue. ![]() enqueue(N) :- It insert element Nto the back of the queue. ![]() The Queue data structure will supports the following operations: Design a Queue (FIFO) data structure using Dynamic Array.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |