I’m making a top-bottom queue. Do I use array or arraylist?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I’m not sure what you mean by “top-bottom” queue, and neither does google, but in general an array is not a good choice for a queue. In queues, you insert at the front and remove from the back (FIFO). In an array, insertion to the front of the array requires copying all of the elements in the existing array over to the right one, requiring O(n) time. If you only have a few items in the queue, that’s not much of an issue, but if you have a lot of items, it’s obviously very wasteful.
A doubly linked list with head and tail pointers would be better, but you should just use a Queue instead.