{"id":576411,"student_id":2589,"content":"{\"html\":\"\u003c!DOCTYPE html\u003e\\n\u003chtml\u003e\\n\u003chead\u003e\\n\\t\u003ctitle\u003eDocument\u003c/title\u003e\\n\u003c/head\u003e\\n\u003cbody\u003e\\n \u003cdiv id=\\\"question\\\"\u003e\\n \u003cp\u003e請依照以下步驟進行綜合練習:\u003c/p\u003e\\n \u003cp\u003e1. 搭配過去學過的演算法知識(廣度優先搜尋),來閱讀練習頁面中的 JavaScript。\u003c/p\u003e\\n \u003cp\u003e2. 修改練習頁面中的 JavaScript,讓執行後網頁上的顯示文字與下方相同。\u003c/p\u003e\\n \u003c/div\u003e\\n \u003cdiv id=\\\"screenshot\\\"\u003e\\n \u003cp\u003e題目:\u003c/p\u003e\\n \u003cdiv id=\\\"log\\\"\u003eloading...\u003c/div\u003e\\n \u003c/div\u003e\\n \u003cdiv id=\\\"screenshot\\\"\u003e\\n \u003cp\u003e解答:\u003c/p\u003e\\n \u003cdiv id=\\\"code\\\"\u003eloading...\u003c/div\u003e\\n \u003c/div\u003e\\n\u003c/body\u003e\\n\u003c/html\u003e\",\"css\":\"* {\\n margin: 0;\\n padding: 0;\\n box-sizing: border-box;\\n font-size: 16px;\\n}\\n\\nhtml, body {\\n width: 100%;\\n height: 100%;\\n background-color: #333;\\n padding: 10px;\\n}\\n\\np {\\n color: white;\\n margin-bottom: 10px;\\n}\\n\\n#log {\\n color: #03F501;\\n padding: 10px;\\n border: 1px solid white;\\n border-radius: 5px;\\n}\\n\\n#code {\\n color: #03F501;\\n padding: 10px;\\n border: 1px solid white;\\n border-radius: 5px;\\n overflow-x: scroll;\\n}\\n\\n#question {\\n height: 130px;\\n border: 1px solid white;\\n padding: 20px;\\n margin-bottom: 10px;\\n}\\n\\n#screenshot {\\n border: 1px solid white;\\n padding: 20px;\\n margin-bottom: 10px;\\n}\",\"js\":\"function breadthFirstSearch(graph, startNode, targetNode) {\\n const queue = [startNode];\\n const visited = new Set();\\n while (queue.length \u003e 0) {\\n const currentNode = queue.shift();\\n if (currentNode === targetNode) {\\n console.log(`Target node ${targetNode} found!`);\\n return;\\n }\\n visited.add(currentNode);\\n const neighbors = graph[currentNode];\\n for (let i = 0; i \u003c neighbors.length; i++) {\\n const neighbor = neighbors[i];\\n if (!visited.has(neighbor)) {\\n queue.push(neighbor);\\n visited.add(neighbor);\\n }\\n }\\n }\\n console.log(`Target node ${targetNode} not found!`);\\n}\\n\\nconst graph = {\\n A: ['B', 'C'],\\n B: ['A', 'D'],\\n C: ['A', 'E'],\\n D: ['B', 'E', 'F'],\\n E: ['C', 'D', 'F'],\\n F: ['D', 'E']\\n};\\n\\nbreadthFirstSearch(graph, 'A', 'F');\\n\"}","created_at":"2023-07-28T11:17:21.432+08:00","updated_at":"2023-07-31T14:10:05.738+08:00","name":"【綜合練習】路徑搜尋:實作 1 - 解答","language":"web","screenshot":{"url":null},"parent_id":576410,"plugin":"(function () {\n if (!console) {\n console = {};\n }\n var old = console.log;\n var logger = document.getElementById('log');\n logger.innerHTML = \"\"\n console.log = function (message) {\n if (typeof message == 'object') {\n logger.innerHTML += (JSON \u0026\u0026 JSON.stringify ? JSON.stringify(message) : String(message)) + '\u003cbr /\u003e';\n } else {\n logger.innerHTML += message + '\u003cbr /\u003e';\n }\n }\n})();\n\ndocument.querySelector(\"#code\").innerHTML = `\u003cpre\u003e// 廣度優先搜尋演算法\nfunction breadthFirstSearch(graph, startNode, targetNode) {\n const queue = [startNode]; // 創建一個佇列,起始節點作為初始項目\n const visited = new Set(); // 創建一個集合,用於記錄已訪問的節點\n while (queue.length \u003e 0) { // 當佇列不為空時繼續搜索\n const currentNode = queue.shift(); // 從佇列中取出下一個待處理節點\n if (currentNode === targetNode) { // 檢查當前節點是否為目標節點\n console.log(\\`目標節點 \\${targetNode} 找到了!\\`); // 若找到目標節點,輸出訊息並結束搜尋\n return;\n }\n visited.add(currentNode); // 將當前節點標記為已訪問\n const neighbors = graph[currentNode]; // 取得當前節點的鄰居節點列表\n for (let i = 0; i \u003c neighbors.length; i++) { // 遍歷當前節點的鄰居\n const neighbor = neighbors[i]; // 取出一個鄰居節點\n if (!visited.has(neighbor)) { // 如果鄰居節點尚未被訪問過\n queue.push(neighbor); // 將鄰居節點加入佇列(表示待處理)\n visited.add(neighbor); // 標記鄰居節點為已訪問\n }\n }\n }\n console.log(\\`目標節點 \\${targetNode} 未找到!\\`); // 在搜尋結束後仍未找到目標節點,輸出訊息\n}\n\nconst graph = {\n A: ['B', 'C'],\n B: ['A', 'D'],\n C: ['A', 'E'],\n D: ['B', 'E', 'F'],\n E: ['C', 'D', 'F'],\n F: ['D', 'E']\n};\n\nbreadthFirstSearch(graph, 'A', 'F');\n\u003c/pre\u003e`\n","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":32,"hashid":"gk4sp65kn","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":13055946,"file_name":"koding.png","project_id":576411,"asset_id":664887,"created_at":"2023-07-28T11:17:25.231+08:00","updated_at":"2023-07-28T11:17:25.231+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
前往網站頁面
1:1:1
1:1
full
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦