contributed by < evanjack2002
>
linux2019
queue.[ch]
和連帶的檔案The queue contents are represented as a singly-linked list, with each element represented by a structure of type list_ele_t
, having fields value
and next
, storing a pointer to a string and a pointer to the next list element, respectively.
Your task is to modify the code in queue.h
and queue.c
to fully implement the following functions.
q_new
:Create a new, empty queue.q_free
:Free all storage used by a queue.q_inserthead
:Attempt to insert a new element at the head of the queue (LIFO discipline).q_inserttail
:Attempt to insert a new element at the tail of the queue (FIFO discipline).q_removehead
:Attempt to remove the element at the head of the queue.q_size
:Compute the number of elements in the queue.q_reverse
:Reorder the list so that the queue elements are reversed in order. This function should notallocate or free any list elements (either directly or via calls to other functions that allocate or free listelements.) Instead, it should rearrange the existing elements.Two of the functions: q_insert_tail
and q_size
will require some effort on your part to meet therequired performance standards. We require that your implementations operate in time .
透過 driver.py
python script,呼叫 subprocess.call
去執行 qtest
,並使用 qtest
的參數 -f
來輸入測試項目的檔案。
共15個測試項目 trace-01~15,前5個項目各6分,後10個項目各7分,透過 qtest
執行成功與否累加積分,總分100。
maxScores = [0, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]
透過建立 cmd linked list,根據 cmd 執行對應的 operation,如: ih
command 的operation 為 do_insert_head()
。
透過 exception_setup(true)
與 exception_cancel()
,實做執行時間超過 time_limit 的 exception。
exception_setup(true)
sigsetjmp
建立返回 jump 點。alarm(time_limit)
timer。sigalrmhandler
SIGALRM
signal。SIGALRM
的 signal handler 為 sigalrmhandler
。sigalrmhandler
會呼叫 siglongjmp
,做 "nonlocal goto" 到之前建立的 jump 點。exception_cancel()
q_remove_head()
),在沒有超過 time_limit 時,執行到 exception_cancel()
。exception_cancel()
會設定 alarm(0)
來停止 alarm timer。透過 Preprocesser,替換 malloc()
和 free()
。
malloc
的 test_malloc
,來做很多應用。
option malloc xx
command,使 malloc()
有機率回傳 NULL 要不到記憶體配置的狀況。
In time
In time
sed -i "s/alarm/isnan/g" $(patched_file)
用於在 binary 裡,替換 alarm
文字成 isnan
文字,是為了讓 valgrind 不會有 alarm timer 中順利進行。sigsetjmp
and siglongjmp
man page
sigsetjmp()
and siglongjmp()
also perform nonlocal gotos, but provide predictable handling of the process signal mask.參考資料應該列出「第一手材料」
謝謝老師,我在去找找。
apt install build-essential git-core cppcheck clang-format valgrind