Câu hỏi: CSD201 Cấu trúc dữ liệu và giải thuật – Bộ ôn tập cuối kỳ số 4
50 câu trắc nghiệm kèm lời giải của môn CSD201 - Cấu trúc dữ liệu và giải thuật, xếp đúng thứ tự trong đề.
Danh sách câu hỏi
while(S is not empty){ch = top element of the stack S if ch is isolated then remove it from the stack and put it to E
elseselect the first vertex Y (by alphabet order), which is adjacent to ch,push Y to S and remove the edge (ch,Y) from the graph
}the last array E obtained is an Euler cycle of the graph Suppose a multigraph G is given below (view picture). Which of the followings is the Euler cycle from the vertex D, created by above algorithm?
int x = 5;
Node q = new Node(x);
q.prev=null;
q.next = head;
head.prev = q;
head = q;void pop(Object x)
{ if (isEmpty()) return(null);
pool.remove(pool.size()-1);
}Object pop()
{ if (isEmpty()) return(null);
return(pool.removeLast());
}Object pop()
{if (isEmpty()) return;
return(pool.remove(pool.size()-1));
}Object pop()
{ if (isEmpty()) return(null);
return(pool.remove(pool.size()));
}Đáp án đúng: "Object pop() {
if (isEmpty()) return(null);
return(pool.removeLast());}". Vì cuối danh sách được coi là đỉnh ngăn xếp và java.util.LinkedList có sẵn removeLast(), lệnh này vừa tháo nút cuối vừa trả về chính phần tử đó trong một bước, đúng ngữ nghĩa của pop là lấy ra và trả về đỉnh; kiểu trả Object cho phép trả null khi ngăn xếp rỗng. Vì vậy "
void pop(Object x) {
if (isEmpty()) return(null);
pool.remove(pool.size()-1);
}" sai hai chỗ: hàm void không được return(null), lại nhận tham số và không trả gì nên người gọi không bao giờ nhận được phần tử ở đỉnh. "Object pop() {
if (isEmpty()) return;
return(pool.remove(pool.size()-1));}" sai vì hàm khai báo trả Object mà có lệnh return trống, trình biên dịch báo thiếu giá trị trả về. "Object pop() {
if (isEmpty()) return(null);
return(pool.remove(pool.size()));}" sai vì chỉ số hợp lệ chỉ từ 0 đến size()-1, nên remove(pool.size()) luôn vượt biên và ném IndexOutOfBoundsException.
Node q = new Node(x);
q.prev=null;
q.next = head;
head.prev = q;
head = q;while(there are more characters in the word to read){read a character if a character is '*' then dequeue and write the dequeued character to the screen
else
enqueue the character into the queue
}What is written to the screen for the input ""Go*odA**fter**No**o***n" ?
oAdoretfooGoodAfteroodAfterooGoodAfterNint x = 5;
Node f = p.prev; //prev is a link to predecessor node
Node q = new Node(x);
q.prev = f; q.next = p;
f.next = q; p.prev = q;void fun(int n)
{if(n > 0)
{System.out.print(" " + n % 5);
fun(n/3);
}
}What is the output when the statement fun(17); is run?
Node p1, p2;
p1 = new Node(x);
p2 = p.next;
p.next = p1; p1.prev = p;
p1.next = p2; p2.prev = p1;