![]() ![]() import from "my-app",įor (let i = queuedCount i this. The problem here is this, when I push the dequeue button I basically need to reindex everything so that after I dequeue an element the element at index 1, now takes the position index 0 and basically I always want to dequeue the item at element 0. ![]() In the dequeue function, I am setting each element of the dequeue array equal to each element of the original array by incrementing the dequeueCount variable. What I am trying to do right now is with the Enqueue button I am adding items to an array while incrementing the variable count by 1 with each push of the button so as to add each new user input to the next array position. In the array, we add elements circularly and use two variables to keep track of the. dequeue: Removes and returns the first element from the queue. Rather than printing 'the queue is empty cant dequeue', and returning the default value of the value variable, I think its better to throw an exception and catch it. This a simple implementation of Queue Abstract Data Type uses an Array. enqueue: Adds element e to the back of queue. What I know about queues is pretty limited, I know they are similar to stacks but rather than being Last-In-First-Out (LIFO) as stacks are they are First-In-First-Out (FIFO) so basically whatever elements go into the array first will be taken out of the array first. 2 Answers Sorted by: 6 I think the value variable in the dequeue method is potentially destructive. I have two functions one to dequeue and one to enqueue a user-inputted item from/to an array respectively.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |