what is the basic difference between stack and queue?

后端 未结 11 842
死守一世寂寞
死守一世寂寞 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:43

    STACK: Stack is defined as a list of element in which we can insert or delete elements only at the top of the stack

    Stack is used to pass parameters between function. On a call to a function, the parameters and local variables are stored on a stack.

    A stack is a collection of elements, which can be stored and retrieved one at a time. Elements are retrieved in reverse order of their time of storage, i.e. the latest element stored is the next element to be retrieved. A stack is sometimes referred to as a Last-In-First-Out (LIFO) or First-In-Last-Out (FILO) structure. Elements previously stored cannot be retrieved until the latest element (usually referred to as the 'top' element) has been retrieved.

    QUEUE:

    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

    A queue is a collection of elements, which can be stored and retrieved one at a time. Elements are retrieved in order of their time of storage, i.e. the first element stored is the next element to be retrieved. A queue is sometimes referred to as a First-In-First-Out (FIFO) or Last-In-Last-Out (LILO) structure. Elements subsequently stored cannot be retrieved until the first element (usually referred to as the 'front' element) has been retrieved.

提交回复
热议问题