programming assignment with structures, linked list and queues.
by: Skyler Knezevic, M.S. Candidate CSE1002 – Spring 2019
1
Assignment 4
Due Wednesday, April 24, 2019 by 23:59:59 You are required to write and submit a C program for the following problem: Submitted file name must be: eventList.c project id: eventList Assignment_4 folder under File on Canvas has some input/output files for testing your code Note: Assignment 4 has two parts. Both parts should be done in one C program. Part 1: Two friends decided to make a calendar with event by merging their personal calendars. Friend
A has a personal calendar that is stored in a linked list and Friend B stored events in a queue.
Write a code that merges events from an array queue into linked list events at alternating
positions.
You will have following structures: the EVENT_DATE struct:
• an integer for the month (1..12) • an integer for the day (1 .. 31)
the EVENT struct:
• a char array (length 20) for the event’s title • an EVENT_DATE struct to hold the event’s date • a pointer to the next EVENT
You need following functions:
- insert_events_linkedList – inserts a node in the linked list each time it is called.
- insert_events_queue – inserts an element in the queue. The queue must be built as an
array.
- merge_lists – merges the queue into the linked list. In case the queue has more elements
than the linked list, leave the rest of the elements in the queue for this part.
- print_linkedlist – prints the linked list before and after inserting elements.
- print_queue – prints the queue before elements are inserted, and after inserting prints the
elements that are left in the queue. If it is empty print “Empty”.
by: Skyler Knezevic, M.S. Candidate CSE1002 – Spring 2019
2
Example 1: Before Meregeing:
After Meregeing:
Note: The nodes of queue should only be inserted when there are positions available. Example 2: Before Meregeing:
After Meregeing:
by: Skyler Knezevic, M.S. Candidate CSE1002 – Spring 2019
3
Part 2: Create a doubly linked list and insert all elements from the above singly linked list into it in
ascending order based on the date. After sorting, check if your queue is empty. In case that the
queue still has elements, insert them into the doubly linked list so that doubly linked list stays
sorted.
You will need following functions:
- insert_doubly – inserts elements to a doubly linked list in order based on date. Note: If
two or more events are happing on the same date, sort them alphabetically.
- add_queue – adds elements from queue to the list if there is any left so that list stays in
the order.
Example3: After inserting into the doubly linked list:
After inserting elements from queue:
Error checking
You will have to perform error checks during the run time of your program. These errors will not cause the program to terminate.
- Wrong data – you should check if dates entered are valid. Non-valid dates should be ignored. Do not ask user to re-enter those dates, just print the invalid date of the event and do NOT add that event into the list.
- Event title too long – check if the event’s title is 20 characters or less. In the case that is longer than 20 characters print an error message and do NOT add that event into the list.