contributed by < lineagech
>
認真看作業要求,除了提及如何逐步達到要求,還需要進行:
還未達成符合預期目標,請繼續付出!
Implement linked list's insert/delete, head/tail, new, free, reverse:
q_new: Create a new, empty queue.
q_free: Free all storage used by a queue.
q_insert head: Attempt to insert a new element at the head of the queue (LIFO discipline).
q_insert tail: Attempt to insert a new element at the tail of the queue (FIFO discipline).
q_remove head: 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 not allocate or free any list elements (either directly or via calls to other functions that allocate or free list elements.) 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 the required performance standards. Naive implementations would require O(n) steps for a queue with n elements.
We require that your implementations operate in time O(1)
Due to O(1) time complexity requirement,need to additionally have tail of queue:
Handling null bytes is easily ignored. When copying from value, we should notice if buffer size is larger or smaller than value length.
found that re-define malloc and free:
- To record size and # of malloc for allocated memory block in double linked list
- Notice there is a zero-length array, that is, Declaring zero-length arrays is allowed in GNU C as an extension. A zero-length array can be useful as the last element of a structure that is really a header for a variable-length object:. So we can know the payload address of continuous memory
- fail_allocation() generate allocate memory failed condistion according the probability
- Every time there will be block_ele_t allocated when calling malloc, and put some information like header and footer.
- It can be seen that footer is used to detect memory corruption
When typing make test
, it will execute scripts/driver.py
to run commands:
We can just run each pre-set commands in traceDict
and run runTrace
for each:
If something causing wrong, the srcipt will return a flag to rell the score should be counted or not. And finally print the score as we see.