Você está na página 1de 3

10/28/13

computer science - What are practical applications of Queues? - Stack Overflow

Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Tell me more

What are practical applications of Queues?

What are practical applications of Queues in Computer Science. Where do we use them and why? I heard that we use them in Video Games and Computer Simulation programs, is that true? Why? Apart from these two areas what are other practical applications of Queues as a data structure?
computer-science queue

edited Mar 6 '10 at 14:49 skaffman 170k 26 339 428

asked Mar 6 '10 at 14:45 Muhammad Maqsoodur Rehman 2,678 14 46 79

Have you ever waited in a line? Anything that has to wait for a service, capability, etc... must wait in a line or what the English call a queue. kenny Mar 6 '10 at 14:48 They are used any time you want to pass something around in some sort of order. Travis Gockel Mar 6 '10 at 14:49

13 Take your profile, for example. There's a queue of 20 questions that you've asked, all waiting for you to
accept answers for them. skaffman Mar 6 '10 at 14:49

10 Answers
Queues are used for any situation where you want to efficiently maintain a First-in-first out order on some entities. These situations arise literally in every type of software development. Imagine you have a web-site which serves files to thousands of users. You cannot service all requests, you can only handle say 100 at once. A fair policy would be first-come-first serve: serve 100 at a time in order of arrival. A Queue would definitely be the most appropriate data structure. Similarly in a multitasking operating system, the CPU cannot run all jobs at once, so jobs must be batched up and then scheduled according to some policy. Again, a queue might be a suitable option in this case.
answered Mar 6 '10 at 14:53 Il-Bhima 5,191 1 19 36

Stacks are used for the undo buttons in various softwares. The recent most changes are pushed into the stack. Even the back button on the browser works with the help of the stack where all the recently visited web pages are pushed into the stack. Queues are used in case of printers or uploading images. Where the first one to be entered is the first to be processed.
answered Nov 1 '12 at 18:14

stackoverflow.com/questions/2392824/what-are-practical-applications-of-queues

1/3

10/28/13

answered Nov 1 '12 at 18:14 Bhavya 51 1 1

computer science - What are practical applications of Queues? - Stack Overflow

I use a queue to prioritise my replying to SO questions. I tried multiprocessing them, but made a complete hash of it.
answered Mar 6 '10 at 14:52 High Performance Mark 42.4k 1 35 72 @High-Performance Mark Maybe with two monitors you could use your two processors (aka brain hemispheres) to process two posts in parallel... but I/O would still suck, for various reasons :-) Pter Trk Mar 6 '10 at 14:54

@Pter Trk: how did you know I'd had a lobotomy ? High Performance Mark Mar 6 '10 at 15:25

All kinds of systems, where requests / jobs / clients are processed by one or more handlers: the incoming items are stored in a queue and when a handler is free, it pops a new item from the queue and starts processing it. This pattern is used in all web servers, among others. See producer-consumer problem.
edited Mar 6 '10 at 14:57 answered Mar 6 '10 at 14:49 Pter Trk 68.1k 11 115 201

Say you have a number of documents to be printed at once. Your OS puts all of these docs in a queue and sends them to the printer. The printer takes and prints each document in the order the docs are put in the queue, ie, First In, First Out. In the situation where there are multiple users or a networked computer system, you probably share a printer with other users. When you request to print a file, your request is added to the print queue. When your request reaches the front of the print queue, your file is printed. This ensures that only one person at a time has access to the printer and that this access is given on a first-come, first-served basis.
answered Mar 6 '10 at 14:56 Zaki 2,978 3 13 27

Algorithms and data-structures are strongly tight together So , usually using a Stack depends on the Algorithm which will manipulate the Stack Enqueuing and Dequeuing Which in turn . depends on the application for example , if you are making an appreciation , which will accept input from multiple users , and you have to server them on a "First Come First Service" basis .. which mean your app will serve first request First instead of every time you check the time stamp of each request , and see who is the oldest you should Enqueue each incoming request to a stack and you have only to Dequeue the Stack every time to see the next request
answered Mar 6 '10 at 15:00 Radian 702 7 12

in computer comilation is made by FIRST IN FIRST OUT[FIFO].first line compile first n result print first that is QUEUE.
answered Aug 4 '11 at 16:55 aish 11 1

stackoverflow.com/questions/2392824/what-are-practical-applications-of-queues

2/3

10/28/13

computer science - What are practical applications of Queues? - Stack Overflow


Typical uses of queues are in simulations and operating systems.

O p e r a t i n gs y s t e m so f t e nm a i n t a i naq u e u eo fp r o c e s s e st h a ta r er e a d yt oe x e c u t eo rt h a ta r ew a i t i n gf o rap a r t i c u l a re v e n C o m p u t e rs y s t e m sm u s to f t e np r o v i d ea h o l d i n ga r e a f o rm e s s a g e sb e t w e e nt w op r o c e s s e s ,t w op r o g r a m s ,o re v e nt w os y s t e m Our software queues have counterparts in real world queues. We wait in queues to buy pizza, to enter movie theaters, to drive on a turnpike, and to ride on a roller coaster. Another important application of the queue data structure is to help us simulate and analyze such real world queues.
answered Jan 28 '12 at 5:12 mahboob khan 11 1

Queues are using first in first out concept (FIFO). The first job to arrive is the first to be processed. e.g. OS queues documents for printing in a queue where the printer will only print the first document to arrive and give output
edited Oct 10 at 8:38 axrwkr 1,455 3 8 21 answered Oct 10 at 8:10 eliezer from kisumu poly 11 1

In a breadth-first ("shallowest"-first) search of a graph, you would use a queue to store nodes as you discover them.
answered Apr 7 '10 at 11:53 James M. 2,032 8 24

Not the answer you're looking for? Browse other questions tagged computer-science
queue or ask your own question.

stackoverflow.com/questions/2392824/what-are-practical-applications-of-queues

3/3

Você também pode gostar