Instructions
For this assignment you should place each solution in a separate directory. Each directory should contain a Makefile that builds the code in that directory.
For each problem in the assignment you must include tests using the check
lirbary.
Your Makefile should have targets to
- build your code
- build your tests
- run your tests
- generate code coverage reports in html.
Lab3 explains how to use check
,
write tests and run them as well as how to generate code
coverage reports. Lab2 explains how to use Makefiles.
Problem 1: Binary Trees
You are asked to design a Binary Tree which that can store integers as values and provide the following operations on Binary Trees. The
operations below use BT
as the type for a Binary Tree node. You
are free to design BT
in any way you prefer.
-
bool bt_equal(BT *t1, BT *t2)
given two binary trees return true if the trees contain the same integers at corresponding nodes in the tree. -
BT *mirror(BT *t)
returns the mirror image oft
, e.g, -
bool is_mirror(BT *t1, BT *t2)
returns true ift1
is a mirror image oft2
.
Problem 2: Doubly Linked List
You are asked to provide an implementation of a Doubly Linked List of integers. The operations below use Node
as the type for a doubly linked list node, you are free to design Node
in any way you like. You should provide the following operations on doubly linked lists:
-
Node *create(int element)
creates a new list containing the single elementelement
and returns a pointer to the head of the list. -
void add(int element, Node *list)
addselement
to the end of the list. -
bool contains(int element, Node *list)
return true ifelement
is found inlist
, else returns false. -
void remove(int element, Node *list)
removeelement
fromlist
. Ifelement
is not inlist
thelist
remains unchanged. -
delete_list(Node *list)
deallocates all the element oflist
. The head pointer should now point toNULL
. -
int length(Node *list)
returns the total number of elements inlist
. If thelist
is empty then return 0. -
int get_nth_element(int n, Node *list)
returns then
th element in the list. Ifn
is greater than the size of the list, or less than 0, the program should exit unsuccessfully. -
void add_nth(int element, int n, Node *list)
addselement
to then
-th index in the list moving all existing elements at indexes greater or equal ton
by 1. Ifn
is greater than the size of the list, or less than 0, the program should exit unsuccessfully. -
Node *append(Node *list1, Node *list2)
append the two lists. -
bool equal(Node *list1, Node *list2)
return true if the two lists contain the exact same element at each corresponding index, else, return false.
Problem 3: Priority Queue
You are asked to imlpement a Priority Queue for Tasks.
A Task consists of
- the task id, an integer
- the task owner, a long
-
the task state, which is one of
- suspended
- running
- stopped
Your implementation of the priority queue must support the following operations. The operations use the type Task
to denote a Task and PQ
to denote a priority queue element. You are free to design Task
and PQ
in any way you prefer.
-
PQ *create(Task t, int priority)
creates a new priority queue with one elementt
witht
having prioritypriority
. -
void remove(Task t, PQ *queue)
removes taskt
fromqueue
ift
is inqueue
, elsequeue
remains unchanged. -
Task *pop(PQ *queue)
returns the task with the highest priority inqueue
and removes the task fromqueue
. -
void push(Task t, int priority, PQ *queue)
add taskt
with priotitypriority
intoqueue
. -
int get_max_priority_value(PQ *queue)
returns the value of the highest priority inqueue
. -
int get_min_priority_value(PQ *queue)
returns the value of the lowest priority inqueue
. -
void update_priority(int task_id, int priority, PQ *queue)
updates the priority of all tasks withtask_id
to betask_id
. -
PQ *combine(PQ *queue1, PQ *queue2)
combines the two queues into one. -
void set_to_suspend(int task_id, PQ *queue)
updates the state of task with task idtask_id
to suspended. If there is not task with task idtask_id
in the queue, the queue remains unchanged. -
void set_to_running(int task_id, PQ *queue)
updates the state of task with task idtask_id
to running. If there is not task with task idtask_id
in the queue, the queue remains unchanged. -
void set_to_stopped(int task_id, PQ *queue)
updates the state of task with task idtask_id
to stopped. If there is not task with task idtask_id
in the queue, the queue remains unchanged.
Problem 4: Pick your team members
Send a message to the course staff on Piazza with the CCIS logins of your team members. Teams can have a maximum of 3 team members. We reccommend 3 members for each team.
If you would like to form a team with 2 members you will have to first get approval from the instructor.