Câu hỏi: CSD201 Cấu trúc dữ liệu và giải thuật – Bộ ôn tập thi lại số 3
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 đề. Trang 2/3 — câu 21–40.
Danh sách câu hỏi
while(there are more characters in the word to read){read a character if a character is '*' then pop and write the poped character to the screen
else
push the character into the stack
}What is written to the screen for the input "Good**Morn**i***ng" ?
donrioodonrioMdonrioGdonriMGint x = 5;
Node f = p.prev; // prev is a link to predecessor node
Node q = new Node(x); // Create new node with value x
q.prev = f; q.next = p;
f.next = q; p.prev = q;Node f = head;
while(f.next != tail) f = f.next;
f.next = null;
tail = f;Đáp án đúng: "It deletes the last node.". Vòng lặp while(f.next != tail) f = f.next; dừng lại đúng khi f là nút có liên kết trỏ tới tail, tức nút kế cuối; sau đó f.next = null cắt liên kết tới nút cuối và tail = f dời đuôi lùi về nút kế cuối. Nút cuối cũ không còn ai trỏ tới nên bị loại khỏi danh sách. Vì danh sách có ít nhất 2 nút nên head khác tail và f.next khác null ngay từ đầu, vòng lặp an toàn. Phương án "It deletes node before the last node." sai vì nút kế cuối chính là f và nó được giữ lại làm đuôi mới, không hề bị bỏ. Phương án "It deletes some middle node in the list." sai vì điều kiện dừng neo vào tail nên vòng lặp luôn chạm chính xác vị trí cuối, không phải một nút giữa bất kỳ. Phương án "It does not make any change on the list." sai vì hai lệnh gán cuối đổi thật: một liên kết next bị xoá và biến tail bị trỏ lại.
int x = 5;
Node f = head;
while(f.next != p) f = f.next;
Node q = new Node(x);
q.next = p;
f.next = 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 "HowAre***You**To****Day" ?
owAreYouTHowAreYoHowAreYouwAreYouTovoid push(Integer x)
{ Node p = new Node(x);
p.next = head;
head=p.next;
}void push(Integer x)
{ Node p = new Node(x);
p.next = head;
}void push(Integer x)
{ Node p = new Node(x);
p.next = null;
head=p;
}void push(Integer x)
{ Node p = new Node(x);
p.next = head;
head=p;
}Đáp án đúng: "
void push(Integer x) {
Node p = new Node(x);
p.next = head;
head=p;
}". Ngăn xếp cài bằng danh sách liên kết đơn với đỉnh là đầu danh sách cần đúng hai việc theo đúng thứ tự: cho nút mới trỏ tới nút đang đứng đầu, rồi dời head về nút mới; làm ngược thứ tự thì mất phần còn lại của danh sách. "
void push(Integer x) {
Node p = new Node(x);
p.next = head;
head=p.next;
}" gán head bằng p.next, mà p.next vừa được đặt bằng head, nên head không đổi và nút p bị bỏ rơi, giá trị mới không vào được ngăn xếp. "
void push(Integer x) {
Node p = new Node(x);
p.next = head;
}" nối nút mới vào danh sách nhưng không bao giờ dời head, nên không ai chạm tới p được và kích thước ngăn xếp đứng yên. "
void push(Integer x) {
Node p = new Node(x);
p.next = null;
head=p;
}" cho head trỏ tới nút mới nhưng cắt p.next thành null, tức bỏ sạch mọi phần tử đã đẩy vào trước đó, ngăn xếp chỉ còn một phần tử.
Node q = p.next;
p.next = q.next;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 B, created by above algorithm?