COMP9024 Assignment One

 COMP9024 Assignment One

Objectives
• Give you experience with doubly linked lists
• Understand how to solve set union, set intersection and longest sublist problems
• Give you practice with time complexity analysis
• Give you further practice with C and data structures
Admin
Marks 12 marks. Marking is based on the correctness and efficiency of your code. Your 
code must be well commented.
Group? This assignment is completed individually
Aims
In this assignment, you will implement a set of functions based on the doubly linked list 
defined in MyDLList.c.
The functions you need to implement are shown as follows:
1. DLList *CreateDLListFromFileDlist(const char *filename). This function creates a 
doubly linked list of integers by reading all integers from a text file named filename, 
and returns a pointer to the doubly linked list where each node stores one integer. Assume that adjacent integers in the file filename and the standard input are 
separated by one or more white space characters or a new line character. 
If filename is “stdin”, CreateDLListFromFileDlist (“stdin”) creates a doubly linked list 
by reading all integers from the standard input and the word end denotes the end of 
input. 
This function must check for invalid input. In case of invalid input, it prints an error 
message “Invalid input!” and returns NULL. (2 marks)
2. void printDLList(DLList *u ). This function prints all the elements (integers) of a doubly 
linked list pointed by u in the order from the first node to the last node in the list on 
the standard output, one element per line. (1 mark)
3. DLList *cloneList(DLList *u). This function creates an identical copy of a doubly linked
list u and returns a pointer to the list cloned. (1 mark) 4. DLList *longestSublist(DLList *u). This function returns a doubly linked list that is the 
longest sublist of u. The longest sublist v of a list u is defined as follows:
a. The greatest common divisor of all the elements (integers) of v is not 1 (we 
consider positive divisors only).
b. No other sublist of u contains more elements than v.
Consider a list u = {2, -6, 8, 15, 11,23, 20}. The longest sublist v of u is {2, -6, 8, 20}, 
and the greatest common divisor of all the elements of v is 2. 
Note that the longest sublist of a list may not be unique. Consider a list u = {2, 6, 4, 3, 
9}. There are two longest sublists: v1={2, 6, 4} and v2={6, 3, 9}. 
When analysing the time complexity of your algorithm, you may assume that the 
maximum integer of the input list is a constant. Under this assumption, it takes 
constant time O(1) to check if two integers are mutually prime (i.e., their only divisor 
is 1). (3 marks) 5. DLList *setUnion(DLList *u, DLList *v). This function computes the union of the two 
sets of integers that are stored in the doubly linked lists pointed by u and v, 
respectively, and returns a pointer to the doubly linked list that stores the union. Each 
element (int) of a set is stored in a node of the corresponding doubly linked list.
Given two sets A and B, the union of A and B is a set that contains all the distinct 
element of A and B. For example, assuming that A = {2, 8, 5, 7} and B = {5, 9, 6, 7}, A 
ꓴ B = {2, 8, 5, 7, 9, 6}. Note that in a set, all the integers are not necessarily sorted.
(2 marks) 6. DLList *setIntersection(DLList *u, DLList *v). This function computes the intersection 
of the two sets of integers that are stored in the doubly linked lists pointed by u and 
v, respectively, and returns a pointer to the doubly linked list that stores the 
intersection. Each element (int) of a set is stored in a node of the corresponding 
doubly linked list. (2 marks)
For simplicity, you may assume that all the elements of each input set are distinct 
for both set union and set intersection. Therefore, you do not need to check if a set 
contains duplicates.
Given two sets A and B, the intersection of A and B is a set that contains all the 
elements of A that are also in B. For example, assuming that A = {2, 8, 5, 7} and B = {5, 
9, 6, 7}, A ꓵ B = {5, 7}.
7. void freeDLList(DLList *u). This function frees the space occupied by all the nodes of 
the doubly linked list pointed by u. (1 marks)
Time complexity analysis: For each function, you need to analyze its time complexity in terms 
of big-O notation and put your analysis as comments immediately before the code of the 
function. You may assume that each built-in I/O function such as printf(), malloc() and free(), 
takes O(1) time.
How to submit your code?
1. Go to the assignment one page
2. Click on Assignment Specfication
3. Click on Make Submission
4. Submit your MyDLList.c file that contains all the code.
Plagiarism
This is an individual assignment. Each student must work out his/her own solution without 
help from other people. In particular, it is not permitted to exchange code or pseudocode. 
You are not allowed to use code developed by persons other than yourself. All work 
submitted for assessment must be entirely your own work. We regard unacknowledged 
copying of material, in whole or part, as an extremely serious offence. For further 
information, see the Course Information.

热门主题

课程名

mktg2509 csci 2600 38170 lng302 csse3010 phas3226 77938 arch1162 engn4536/engn6536 acx5903 comp151101 phl245 cse12 comp9312 stat3016/6016 phas0038 comp2140 6qqmb312 xjco3011 rest0005 ematm0051 5qqmn219 lubs5062m eee8155 cege0100 eap033 artd1109 mat246 etc3430 ecmm462 mis102 inft6800 ddes9903 comp6521 comp9517 comp3331/9331 comp4337 comp6008 comp9414 bu.231.790.81 man00150m csb352h math1041 eengm4100 isys1002 08 6057cem mktg3504 mthm036 mtrx1701 mth3241 eeee3086 cmp-7038b cmp-7000a ints4010 econ2151 infs5710 fins5516 fin3309 fins5510 gsoe9340 math2007 math2036 soee5010 mark3088 infs3605 elec9714 comp2271 ma214 comp2211 infs3604 600426 sit254 acct3091 bbt405 msin0116 com107/com113 mark5826 sit120 comp9021 eco2101 eeen40700 cs253 ece3114 ecmm447 chns3000 math377 itd102 comp9444 comp(2041|9044) econ0060 econ7230 mgt001371 ecs-323 cs6250 mgdi60012 mdia2012 comm221001 comm5000 ma1008 engl642 econ241 com333 math367 mis201 nbs-7041x meek16104 econ2003 comm1190 mbas902 comp-1027 dpst1091 comp7315 eppd1033 m06 ee3025 msci231 bb113/bbs1063 fc709 comp3425 comp9417 econ42915 cb9101 math1102e chme0017 fc307 mkt60104 5522usst litr1-uc6201.200 ee1102 cosc2803 math39512 omp9727 int2067/int5051 bsb151 mgt253 fc021 babs2202 mis2002s phya21 18-213 cege0012 mdia1002 math38032 mech5125 07 cisc102 mgx3110 cs240 11175 fin3020s eco3420 ictten622 comp9727 cpt111 de114102d mgm320h5s bafi1019 math21112 efim20036 mn-3503 fins5568 110.807 bcpm000028 info6030 bma0092 bcpm0054 math20212 ce335 cs365 cenv6141 ftec5580 math2010 ec3450 comm1170 ecmt1010 csci-ua.0480-003 econ12-200 ib3960 ectb60h3f cs247—assignment tk3163 ics3u ib3j80 comp20008 comp9334 eppd1063 acct2343 cct109 isys1055/3412 math350-real math2014 eec180 stat141b econ2101 msinm014/msing014/msing014b fit2004 comp643 bu1002 cm2030
联系我们
EMail: 99515681@qq.com
QQ: 99515681
留学生作业帮-留学生的知心伴侣!
工作时间:08:00-21:00
python代写
微信客服:codinghelp
站长地图