Linear table, stack, queue job title

First, multiple choice (2 points each, a total of 30 points)

(1) represents the data within a computer memory, the same physical address and the logical address and is continuous, called (C).
A. Storage structure B. Logical structure C. Sequential storage structure D. Storage Structure

(2) indicates the advantages of using a linear table is a linked list (B).
A. B. facilitate random access Easy to insert and delete operations performed
C. Storage space less than the order table D. The physical order of the elements with the same logical sequence

(3) each node comprises a known single list pointer field next, it is directed to the subsequent node of the node. After the new node is now place the cursor insertion point q to the node pointer p pointing to, the following sequence is correct (C).
. = Q A p.next; p.next = q.next;
. B = p.next q.next; Q = p.next;
. Q.next C = p.next; p.next = Q;
D. p.next = q; q.next = p.next;

(4) If the table of length n linear sequential storage structure, which access the i-th element of the time complexity of the algorithm (A).
A. 0 (l) B. 0 ( n) C. 0 (n2) D. 0 (log2n)

(5) If the table of length n linear sequential storage structure, its time complexity of the algorithm deleting the i-th element of (B).
A. 0 (l) B. 0 ( n) C. 0 (n2) D. 0 (log2n)

(6) First Node single list L empty condition (C)
A. L! = NULL NULL CLnext B. L == == L == NULL DLnext

(7) a single chain length m in length is connected to the algorithm after a single linked list of n time complexity is (B):
A. O (m + n) BO ( n) CO (m) D. (m * n)

(8) 6 by 6 elements, 5, 4, the order of 3, 2, 1, push, push the stack can process, the following is a possible sequence of the stack (B).
A. 1, 4, 3, 5, 2, 6 B. 6, 5, 4, 3, 2, l C. 3, l, 4, 2, 6, 5 D. 3, 6, 5, 4, 2 , l

Does not belong to the stack (9) of the basic operations is (B).
A. Delete the top element B. Delete bottom of the stack element C. D. determine whether the stack is empty The stack is set to an empty stack

(10) if the cycle queue length sequence of M, front to the previous position of the current head elements, rear location of the tail element, assuming the number of elements in the team is always less than M, the number of elements in the current team to (D).
REAR-M Front B. A. Front + - REAR
C. D. M + -1 REAR (REAR Front-M +) M%

(11) if the cycle queue length sequence is n, its head and the tail pointer team respectively represent front and rear, it is determined that full force (C).
A. (REAR -. 1)% = = n-Front B. (Front +. 1)% = = n-REAR
C. (+ REAR. 1)% = = n-Front D. (Front - L) = =% n-REAR

(12) the order link stack Stack has a distinct advantage, (B).
A. B. insert operation more convenient usually do not appear full stack of circumstances
C. stack of empty cases do not appear D. delete operation more convenient

(13) is provided with an empty queue, if the queue entry is the sequence 1, 2, 3, 4, dequeue the legitimate sequence (D).
. 3 A., 2,. 4, B.. 4. 1, 2,. 3, L
C.. 4,. 3, 2, D. L. 1, 2,. 3,. 4

(14) is provided in a single linked list ordered there are n nodes, now requires a new node is inserted such that the single linked list remain orderly, the time complexity of the operation (B).
A. O (1) B. O (n) C. O (n2) D. O (log2n)

(15) is provided leading node in the chain of nodes in the stack structure (data, next), and is the head pointer to the stack. To insert a node indicated by the top of the stack pointer s, shall perform the operations (B).
= S.next head A.; head.next = S;
B. s.next = head.next; head.next = S;
C. s.next = head; head = S;
D. s.next = head; head = head .next;

Second, determine the question (a total of 10 points each 1 minute)

(1) a linear sequence table stored in random access can be realized. (√)
Storage Structure (2) is superior to a linear table sequentially stored. (×)
(. 3) is a linear stack table operation restricted. (√)
each node (4) are exactly the list contains a pointer field. (×)
(. 5), if each element of a data structure of a direct precursor at most, it will be a linear table (×)
(6) push operation, must determine whether the stack is full. (×)
(. 7) regardless of stack memory structure using, as long as not empty, can be arbitrarily delete data elements. (×)
(. 8) If the table using a linear memory address indicating the chain among all of the storage nodes may be continuous or may be discontinuous (√)
(. 9) in a circular queue Q, the determination condition for a full team (Q. +. 1 front) == Q. REAR the MaxSize% (×)
(10) when making the operation of the team chain queue front pointer value does not change. (×)

Third, fill in the blank (2 points, 20 points)

  1. Linear structures, and tree graph structure, between the predecessor and successor nodes, respectively, there is one _, __ _-many and many-__ ______ contact.
  2. Normal sequential storage queue exists using saved _______ ___ false overflow problem, so in practical applications with a multi-cycle chain end to end ___ _____.
    3. Has a sequence of stack S, the elements a1, a2, a3, a4, a5, a6 sequentially into the stack, if the stack is a sequence of six elements a2, a3, a4, a6, a5, a1, the capacity of at least the order of the stack should __3________
  3. Maximum storage space for the circular queue MaxSize = 6, using a less spatial element is determined to effectively stack the stack is full or empty, when the queue head pointer front = 4, when the tail pointer = __ REAR 3___ team when full, the queue There ____5____ elements.
    5, an algorithm should have a finite, certainty, feasibility
    , ___ input and output
    .

Fourth, the application questions (a total of 20 points each 10 points)

1, give the following output program. (Stack for the stack, Queue queue)

void unknown ( Queue Q ) {
        	Stack S;
            int i=0;
            for (i=1;i<11;i++)
              Q. EnQueue (i) ;	
        	while (!Q.IsEmpty ( ) ) 
				{ i=Q.DeQueue () ;  S.Push ( i ); }
        	while (!S.IsEmpty ( ) ) 
				{ S.Pop (); System.out.print(i+"  "); }
}

10 9 8 7 6 5 4 3 2 1

The problem where there is not rigorous, according to the meaning of the questions should be i = Q.DeQueue (); return every time the queue elements and the value of the team assigned to i, then i into the stack, then the stack output should also be i = S.Pop (). The result should be 10,987,654,321. If the queue assignment and neither the stack i, the result should be 11 1,111,111,111,111,111 11 Due to complete execution cycle value of i is 11, 10 enter into the queue 11, the queue 10 is 11 NATURAL

2. please add the following algorithm:
// delete from the list all the values smaller than the min and max elements larger than

void unknown3(LinkNode head, int min, int  max){ 
LinkNode  q=head, p=head.next;
while (p!=NULL) { 
if  (__p.data >= min && p.data <= max (1))
         {q=p; ___(2)p = p.next___}
else {
__q.next = p.next____ (3) ______;
p= q.next ; 
}
}
}

The title Analysis: Note that all values ​​required to delete is smaller than the min and max is larger than the element, when p.data> = min && p.data <= max, when it is between the minimum and maximum values ​​(which may be equal to the minimum and maximum values), if q = p; p = p.next; p-point to the next node. else other cases, it is smaller than min or is larger than max, the p deleted node. Note that p and q is the predecessor node, so it should be q.next = p.next; p = q.next p equal deleted node, and let p at the next node.

Five commonly used algorithms title (20 points)

1. The queue data structures following the chain, implement enqueue and dequeue operations queue function chain. front, rear chain are HOL queue, the tail node (10 minutes)

public class QNode { // 结点结构
	public int data;
	public QNode next;

	public QNode(int data, QNode next) {
		this.data = data;
		this.next = next;
	}
}

public class LinkQueue { // 队列结构
	public QNode front;
	public QNode rear;

	public boolean deQueue() {
		if (front == null) {
			System.out.println("队列为空,无法出队!!");
			return false;
		}
		QNode p = front; // p指向队头结点
		front = p.next; // front指向p的后继
		if (p == rear) // 如被删结点也是队尾结点
			rear = null; // rear置空
		return true; // 返回出队成功标志;
	}

	public void enQueue(int e) {
		QNode p = new QNode(e, null);
		if (front == null) {
			front = p;
			rear = p;
		} else {
			rear.next = p;
			rear = p;
		}
	}
}

2, ListNode comprising next, data members of the public, can be read directly by p.next next node, p.data read data, write a function algorithm, to remove all non-decreasing value from the sorted linked list in a same redundant elements. the first node of the linked list is ordered La, (prompt algorithm, define two nodes p and q, q initial point to the first node, the first node points p, q precursor is p, when p junction point is not empty, it is determined whether data p and q same node, if the same, then the deleted node p) (10 minutes)

public static void deleteSameNode(ListNode la) {
		ListNode p, q;
		if (la == null)
			return;
		q = la;
		p = la.next;
		while (p != null) {
			if (p.data > q.data) {
				q = p;
				p = p.next;
			} else {
				q.next = p.next;
				p = q.next;
			}
		}
	}
Published 141 original articles · won praise 28 · views 10000 +

Guess you like

Origin blog.csdn.net/weixin_42554191/article/details/103978131