difference between stack and queue

What is the difference between stack and queue?

Solution: (1). The queue is first in, first out, and the stack is first in, last out.

(2).  " Limitations " on insertion and deletion operations .

A stack is a linear list that restricts insertion and deletion to only one end of the list.     

A queue is a linear list restricted to inserts on one side of the table and deletes on the other.  

(3). The speed of traversing data is different. The stack can only take data from the head, that is, the first put in needs to traverse the entire stack before it can be taken out, and when traversing the data, it has to open up a temporary space for the data to maintain the consistency of the data before the traversal. The queue is different. It is traversed based on the address pointer, and it can be traversed from the beginning or the end, but it cannot be traversed at the same time, and there is no need to open up temporary space, because the data structure is not imaged during the traversal process, and the speed is much faster.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325753287&siteId=291194637