what is the basic difference between stack and queue?

后端 未结 11 853
死守一世寂寞
死守一世寂寞 2020-12-07 08:09

What is the basic difference between stack and queue??

Please help me i am unable to find the difference.

How do you differentiate a stack a

11条回答
  •  一向
    一向 (楼主)
    2020-12-07 08:40

    STACK:

    1. Stack is defined as a list of element in which we can insert or delete elements only at the top of the stack.
    2. The behaviour of a stack is like a Last-In First-Out(LIFO) system.
    3. Stack is used to pass parameters between function. On a call to a function, the parameters and local variables are stored on a stack.
    4. High-level programming languages such as Pascal, c, etc. that provide support for recursion use the stack for bookkeeping. Remember in each recursive call, there is a need to save the current value of parameters, local variables, and the return address (the address to which the control has to return after the call).

    QUEUE:

    1. Queue is a collection of the same type of element. It is a linear list in which insertions can take place at one end of the list,called rear of the list, and deletions can take place only at other end, called the front of the list
    2. The behaviour of a queue is like a First-In-First-Out (FIFO) system.

提交回复
热议问题