This shows you the differences between two versions of the page.
queue_and_array [2022/02/28 13:50] scott |
queue_and_array [2022/02/28 13:55] (current) scott |
||
---|---|---|---|
Line 8: | Line 8: | ||
</code> | </code> | ||
- | One thing to note in the code above is that we pass the address of ''myQueue'' to ''queue_init''. We do this for the sake of efficiency in 'C' and also because this is what ''queue_init()'' expects. The following figure shows what ''myQueue'' would look like right after a call to ''queue_init()''. Note that enough memory for 5 elements has been allocated. But, as I said before, this queue can only hold 4 elements. | + | One thing to note in the code above is that we pass the address of ''myQueue'' to ''queue_init()''. We do this for the sake of efficiency in 'C' and also because this is what ''queue_init()'' expects. The following figure shows what ''myQueue'' would look like right after a call to ''queue_init()''. Note that enough memory for 5 elements has been allocated. But, as I said before, this queue can only hold 4 elements. |
{{ ::queueinit.jpg?300 |}} | {{ ::queueinit.jpg?300 |}} | ||
Line 22: | Line 22: | ||
{{ ::queuetwopops.jpg?300 |}} | {{ ::queuetwopops.jpg?300 |}} | ||
- | As shown, ''indexOut'' has moved up two locations. Now, let's say that we want to "push" two new values onto our queue. When "pushing" a new value, the queue would need to check if it is full. It is not because, if indexIn is incremented and wraps around to location 0, it will not be equal to ''indexOut'' because ''indexOut'' now has the value of 2. | + | As shown, ''indexOut'' has moved up two locations. Now, let's say that we want to "push" two new values onto our queue. When "pushing" a new value, the queue would need to check if it is full. If indexIn is incremented and wraps around to location 0, it will not be equal to ''indexOut'' because ''indexOut'' now has the value of 2. |
Now, let's look at the queue after "pushing" two new values (51.5 and 49.2). | Now, let's look at the queue after "pushing" two new values (51.5 and 49.2). |