Joke Collection Website - Joke collection - Cheng's 24 jokes: What's the difference between a pile and a queue?

Cheng's 24 jokes: What's the difference between a pile and a queue?

1. queue FIFO, stack FIFO.

2. "Restrictions" of insert and delete operations. Stack is a linear table and can only be inserted and deleted at one end of the table. Queue is a linear table, which can only be inserted at one end of the table and deleted at the other. From the perspective of "data structure", they are all linear structures, that is, the relationship between data elements is the same. But they are completely different data types. Apart from their different basic operation sets, the main difference is the "restriction" on insert and delete operations. Stack and queue are two linear data structures widely used in programming. They are characterized by the particularity of basic operation. Stacks must operate according to the "last in, first out" rule, while queues must operate according to the "first in, first out" rule. Compared with linear tables, their insertion and deletion operations are more constrained and restricted, so they are also called restrictive linear table structures.

3. The speed of traversing data is different. Stack can only fetch data from the beginning, that is, it needs to traverse the whole stack before it can be fetched. Moreover, it is necessary to open up temporary space for data when traversing the data, so it is much faster to keep the consistency of the queue before traversing the data. It can traverse from the beginning or the end based on the address pointer, but it can't traverse at the same time, and it doesn't open the temporary space, because there is no image in the data structure during the traversal.

Stack is a linear table and can only be inserted and deleted at one end of the table.

Queue is a linear table, which can only be inserted at one end of the table and deleted at the other end.

From the perspective of "data structure", they are all linear structures, that is, the relationship between data elements is the same. But they are completely different data types. Apart from their different basic operation sets, the main difference is the "restriction" on insert and delete operations.

Stack and queue are two linear data structures widely used in programming. They are characterized by the particularity of basic operation. Stacks must operate according to the "last in, first out" rule, while queues must operate according to the "first in, first out" rule. Compared with linear tables, their insertion and deletion operations are more constrained and restricted, so they are also called restrictive linear table structures. The insertion and deletion operations of linear tables and stacks and queues can be compared as follows:

Linear table

Insert (l, i, x)

( 1≤i≤n+ 1)

Delete (l, i)

( 1≤i≤n)

If the linear table allows insertion and deletion anywhere in the table.

shed

Insert (l, n+ 1, x)

Delete (l, n)

Stacks are only allowed to be inserted and deleted at the end of the footer.

long queue

Insert (l, n+ 1, x)

Delete (l, 1)

Queues can only be inserted at the end of the table and deleted at the header.