Board logo

標題: APCS_觀念題_10503_6 [打印本頁]

作者: 方浩葦    時間: 6 天前 10:33     標題: APCS_觀念題_10503_6

本帖最後由 方浩葦 於 2024-9-14 10:37 編輯

List是一個陣列,裡面的元素是 element, 它的定義如右。List 中的每一個 element 利用next 這個整數變數來記錄下一個 element在陣列中的位置,如果沒有下一個 element,next 就會記錄-1。所有的 element 串成了一個串列 (linked list)。例如在 list 中有三筆資料
[attach]19754[/attach]
它所代表的串列如下圖
[attach]19755[/attach]
RemoveNextElement 是一個程序,用來移除串列中current 所指向的下一個元素,但是必須保持原始串列的順序。例如,若current 為3 (對應到 list[3]),呼叫完RemoveNextElement 後,串列應為
[attach]19756[/attach]

請問在空白部分,應該填入的程式碼為何?
  1. struct element
  2. {
  3.       char data; int next;
  4. }
  5. void RemoveNextElement (element list[], int current)
  6. {
  7.       if (list[current].next != -1)
  8.       {
  9.             /*移除 current 的下一個 element*/

  10.            ______________________________
  11.       }
  12. }
複製代碼
(A)        list[current].next = current ;
(B)        list[current].next = list[list[current].next].next ;
(C)        current = list[list[current].next].next ;
(D)        list[list[current].next].next = list[current].next ;




歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/) Powered by Discuz! 7.2