![]() ![]() To wrap the tail, and a similar one for the head. Thus you'll need a statement like if(tail = MAX-1) This results in an added complexity: When either the tail or the head gets to the end of the array, it must wrap around to the beginning. The tail will follow the head along the array as items are added and removed from the queue. Items are on the queue at the tail (like the last customer getting in line at the bank) and removed from the queue at the head. as the stack has, you'll need two variables for a queue: one called head to point to the head of the queue, and one called tail to point to the tail. However, instead of a single int variable called top. These are equivalent to push () and pop() in the stack class.īoth a queue and a stack use an array to hold the data. Besides a constructor, it should have two functions: one gcue. Rewrite the STAKARAY program from this chapter to incorporate a class called queue called put() to put a data item on the queue, and one called get () to get data from the instead of a class called stack. A queue is like a line of customers in a bank: The first one to join the queue is the first one served. That is, a stack uses a last-in-first-out (LIFO) approach, while a queue uses first-in-first-out (FIFO). The difference is that in a stack the last data item stored is the first one retrieved, while in a queue the first data item stored is the first one retrieved. A queue is a data storage device much like a stack. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |