2022q1 Homework1 (lab0)
contributed by < AxotZero
>
> My UBUNTU haven't install Chinese Input Tool.
- Because of personal reasons, I was late to join the course. I started watching youtube videos on 02/19 and finish the basic implementation of queue.c on 02/21. Still have a long journey to completely finish HW1.
Show me the code rather than murmur!
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
jserv
實驗環境
針對佇列的操作
q_new
q_free
q_insert_head, q_insert_tail
Due to the same behavior of q_insert_head and q_insert_tail that both of them need to new an element, I create a function new_element.
Thanks for laneser 開發紀錄 (lab0). I improve function new_element with strdup.
q_remove_head, q_remove_tail
Due to the same behaviour of these two, I create a function q_remove wich remove the target node and copy the value of removed node to sp.
q_size
q_delete_mid
slow, fast pointer version.
Utilize prev pointer version
search by both sides.
q_delete_dup
Searches the start node and end node of duplicate string list, removed duplicate list and concat to remove_head. At the end of the algorithm, q_free(remove_head). In the future improvement, this operation may can be executed when the system is not busy.
q_swap
q_reverse
q_sort
Add "shuffle" command to qtest
- I create
extra_func.h
and extra_func.c
to write the code for shuffle
- There are two version of shuffle
- q_shuffle: need to for-loop to search the node we want to swap
- Time Complexity:
O(n^2)
- Space Complexity:
O(1)
- q_shuffle_dp: store all the address to a list then we can avoid the for-loop to search the node
- Time Complexity:
O(n)
- Space Complexity:
O(N)
- Hence, I add two commands.
shuffle_dp will also be used to compare merge_sort.
Compare my merge_sort and linux/list_sort.c
-
I write a new trace-19-compare_sort.cmd
which generate 750,000 elements to sort and contains three kinds of string aaaa
, cccc
, eeee
-
comparison of my_sort and linux_sort in three cases.
Cases |
my_sort |
linux_sort |
sorted array |
0.278s |
0.15s |
reversed sorted |
0.273s |
0.154s |
shuffled |
1.236s |
0.744s |
Tiny Web server
First Development process - git commit
- Copy most of the code of tiny web server to my
extra_func.c
.
- Add following code to
extra_func.h
- Add command to
qtest.c
and overwrite function run_console
, cmd_select
to console.c
from lab01-tiny-web-server.
- remove all cppcheck warning and errors.
- Still try to figuring out whether there is a better way to avoid
- warning: sscanf() without field width limits can crash with huge input data. [invalidscanf].
- The following is my current solution.
- The solution of LJP-TW
- The web server now can work, but met two error:
- Diffirent behaviour between curl and browser
- If I send a command from through curl, the program will execute correctly

- If I send a command from the chrome browser, the program will execute the command at most three times. I think this is because of the auto-retry of chrome browser.

- If I run web server, any command from the console will get into infinite for-loop

Bug Fix
- Infinite for-loop
- In function
cmd_select
, I forgot to delete the condition if(has_infile)
while we have user input. It leads cmdline = readline()
will never be executed which makes the buffer never be clear. Hence, the select()
always detect user input and leads to infinite for loop.
