11.07.2015 Views

Encyclopedia of Computer Science and Technology

Encyclopedia of Computer Science and Technology

Encyclopedia of Computer Science and Technology

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

queue 397To add an item, the tail pointer is moved back one location<strong>and</strong> the item is stored there. To remove an item, thehead pointer is simply moved back one location. (The datathat had been pointed to by the head pointer can be eitherretrieved or discarded, depending on the application.)In actuality it’s not quite so simple. As items are addedto the queue, the tail pointer keeps moving back in memorywith the head pointer trailing behind as items are deleted. Ifthe queue is sufficiently active (many items are being added<strong>and</strong> removed), the queue will end up “crawling” throughmemory somewhat like a worm until all the memory isconsumed.In a real line at the supermarket, as a customer leavesthe checkout st<strong>and</strong>, each <strong>of</strong> the persons in line movesup one space. In a computer queue this could be accomplishedby moving each item up one location wheneveran item is removed at the head. However, having to moveall the data items each time one is changed would be veryinefficient. Instead, one could allow the head <strong>of</strong> the queueto move only up to some specified location. At that point,the head is moved back to the beginning <strong>of</strong> the memoryblock, <strong>and</strong> thus the space that had been vacated by thetail as it moved up is reutilized. In effect this wraps thememory around into a circle, so this is called a circularqueue.Further ReadingBrookshear, J. Glenn. <strong>Computer</strong> <strong>Science</strong>: An Overview. 6th ed. Reading,Mass.: Addison-Wesley, 2000.Skiena, Steven S. “Priority Queues.” Available online. URL: http://www2.toki.or.id/book/AlgDesignManual/BOOK/BOOK3/NODE130.HTM. Accessed August 17, 2007.Suh, Eric. “The Queue Data Structure.” Available online. URL:http://www.cprogramming.com/tutorial/computersciencetheory/queue.html. Accessed August 17, 2007.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!