tags:

views:

317

answers:

5

Can you give an example where the Queue data structure can be specially helpful

+3  A: 

All of these questions are easily googled. Do your homework on your own.

Geo
Not an answer. -1
Hardwareguy
That is pretty harsh for asking a question about a data structure.
sgmeyer
+1, just look at the author's list of questions.
David
Downvoters, look at Neda's questions in the last 15 minutes and Geo's history, and you'll see that the harshness was well justified.
Paul Tomblin
Is it up to StackOverflow users to police students who want us to solve their homework for them?
Daniel Lew
Daniel, have you checked the questions neda/johanna asked ?
Geo
I agree Geo that he has asked many google type questions, but this should have been posted as a comment and not an answer, that is why some people tend to downvote this. The way SO works is , If you're not going to answer the question then don't post an answer, thats what comments are for.
TStamper
A: 

In the case that you need to process requests in the order that they are received you would use a Queue. Or a FIFO type structure...first in first out...which preserves the request order. To take it further you could use an offline queue similar to MSMQ so disconnect the request from the actual request taker. Say you have a website that needs to send emails. This is a perfect place for a queue where the website stashes the request in the queue for an offline processor so that the web site is not directly tied to the SMTP server that is needed for processing the mail. This then frees up the worker thread on the web site to process web requests.

Andrew Siemer
A: 

queue has many uses in algorithms such as breadth first search. and that is very useful.

Victor
+6  A: 

Queues are most commonly used for scheduling and request handling applications.

For example, anything where you have one process creating requests and another process handling the requests you would use a queue to hold the requests.

Normally a queue is in FIFO order - requests are processed in the order they are received, but they can also be ordered in other ways (a priority queue for example).

A few examples:

  1. An operating system scheduling threads for execution on a CPU would use a queue to determine which thread is next to execute.

  2. A web server handling HTTP requests would use a queue to pass requests on to threads that will actually server up the web pages.

  3. A printer handling requests for print jobs.

Eric Petroelje
A: 

In some cases, items can be (safely) pushed onto and pulled off of queue structures by multiple threads. For example, say you want only 5 simultaneous connections to a credit card processor. 5 threads can be started and checking (waiting) for items to appear on the queue. Requests to process credit cards are placed into that queue structure by other threads would be processed as soon as possible. (That's oversimplified. There are many other considerations, like waiting for a response, thread safety, concurrency, locking, mood of the developer, phase of the moon...)

mikesomeone