Data structure notes 3 stacks and queues

Data structure notes 3 stacks and queues

Preface

Take notes on stacks and queues.

Data structure notes 2 linear table

Mental framework

Three, stack and queue

exercise

Multiple choice

\16. If it is known that the incoming sequence of a stack is 1, 2, 3,..., n, its output sequence is p1, p2, p3,..., pN, if pN is n, then pi is ().

A. i B. ni C. n-i+1 D. Uncertain
\17. The input sequence of a stack is 123...n, if the first element of the output sequence is n, output the i-th (1<=i< =n) elements are ().

A. Not sure B. n-i+1 C. i D. ni
\18. There are six elements 6,5,4,3,2,1 into the stack in the order, and ask which of the following is not a legal pop sequence ? ()

A. 5 4 3 6 1 2 B. 4 5 3 1 2 6
 C. 3 4 6 5 2 1 D. 2 3 4 1 5 6
\19. Suppose the stack input sequence is 1, 2, 3, 4, then () It cannot be its pop sequence.
 A. 1, 2, 4, 3, B. 2, 1,
 3, 4, C. 1, 4, 3, 2, D. 4, 3, 1, 2, E. 3 , 2, 1, 4

20. The common point of stack and queue is ().

A. All are first-in first-out B. All are first-in-last-out
 C. Only insert and delete elements at the endpoints are allowed D. Nothing in common

\21. Assuming that the elements of the circular queue are stored in the array A[m], and the head and tail pointers are front and rear respectively, the number of elements in the current queue is ().

A.(rear-front+m)%m   B.rear-front+1
 C.(front-rear+m)%m     D.(rear-front)%m

\22. Suppose the subscript range of the circular queue storage space is 0...n-1, when the tail pointer of the queue is rear (rear=0 at the beginning) and the queue length is len, the position of the head element in the circular queue is _________.

A. rear - only B. rear - only +1

C. (rear - len + 1)% n D. (rear - len + n)% n

\23. The circular queue is stored in the array A[0...m], the operation when enqueuing is ().

A. rear=rear+1 B. rear=(rear+1) mod (m-1)
 C. rear=(rear+1) mod m D. rear=(rear+1)mod(m+1)

\24. For a circular queue with a maximum capacity of n, the tail pointer is rear and the head of the team is front, and the condition for the team to be empty is ().

A. (rear+1) MOD n=front B. rear=front
 C.rear+1=front D. (rear-l) MOD n=front

\27. If the input sequence is 1, 2, 3, 4, with the help of a two-way team with limited input

Column, the impossible output sequence is __.

​ A)2,4,3,1 B)3,1,2,4

​ C)4,1,3,2 D)4,2,3,1

16.D 17.B 18.C 19.D 20.C

21.A 22.D 23.D 24.B 25.B 26.C 27.D

True or False

() The stack is a necessary structure for implementing subroutines such as procedures and functions.

() Stack is a linear table in which insertion and deletion operations are limited to one end of the table.

() If the input sequence is 1,2,3,4,5,6, the sequence 3,2,5,6,4,1 can be output through a stack.

() Deleting an element from the stack represented by the sequential storage structure may cause the movement of data elements in the stack.

() The stack can be represented by either a sequential storage structure or a chain storage structure.

() Queue is a linear table in which insert and delete operations are performed on both ends of the table, and it is a first-in-last-out structure.

() Regardless of whether the queue adopts a sequential storage structure or a chain storage structure, the time complexity of the in-queue and out-queue operations is O(1).

() A circular queue is a queue represented by a circular linked list.

() Queue and stack are linear tables with limited operations, and only allow operations on both ends of the table.

19.√ 20.√

21.√ 22.X 23.√ 24.X 25.√ 26.X 27.X

Short answer

Queue problem: train outbound sequence

Stack element inversion

The circular linked list queue realizes queue initialization, queue entry, and queue exit.

Thoughts

This part is actually quite interesting and very common in life.

For example, the exit and entry of the browser is a stack, last in first out.

For example, the mobile phone is limited to five background applications, when you open multiple applications, first in, first out. Is a queue

In addition, the recursion commonly used in programming is a stack.

Update address: GitHub

For more content, please pay attention: CSDN , GitHub , Nuggets

Guess you like

Origin blog.csdn.net/weixin_42875245/article/details/109175478