Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
As we know, list can be treated as superset of queue(don't go on literal meaning). Like in list we can insert, delete element from anyplace while Queue is the specialized version of list( u can also implement queue using other data structure too). SO why don't we directly use list instead of queue.
Posted

1 solution

Because an API should not allow anything beyond the intended use. If I were to put a function into an API that returns a list as a result that in truth is a queue, then programmers calling that function might assume it's ok to add elements at the top. Whether or not your API documentation warns against that is irrelevant - you can't assume others will read it.
 
Share this answer
 
v2
Comments
Rahul@puna 21-Feb-14 5:00am    
@Stefan So you are saying that queue is just for specific purpose and it let people know about its behaviour that what it is intended for. That's all why queue is introduced. Am I correct..
Stefan_Lang 21-Feb-14 5:03am    
Indeed. There may also be other considerations, such as performance and memory footprint: list implementations are usually bidirective and use two pointer to link with other lements per list element. Queues only need one pointer as they are one-directional. But that is usually of little concern.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900