Answered step by step
Verified Expert Solution
Question
1 Approved Answer
/ / DO NOT INCLUDE ANY OTHER LIBRARIES / FILES #include pointer.h / / / / / / / / / / / /
DO NOT INCLUDE ANY OTHER LIBRARIESFILES
#include "pointer.h
In this assignment, you can assume that function parameters
are valid and the memory is managed by the caller
Returns the area of a rectangle
The shape is guaranteed to be a valid rectangle
double rectangleareavoid shape
rectanglet rectangle rectangletshape;
IMPLEMENT THIS
return ;
Returns the area of an equilateral triangle
The shape is guaranteed to be a valid triangle
The area of an equilateral triangle is sqrt times length
squared
double triangleareavoid shape
trianglet triangle triangletshape;
IMPLEMENT THIS
return ;
Returns the perimeter of a rectangle
The shape is guaranteed to be a valid rectangle
double rectangleperimetervoid shape
rectanglet rectangle rectangletshape;
IMPLEMENT THIS
return ;
Returns the perimeter of an equilateral triangle
The shape is guaranteed to be a valid triangle
double triangleperimetervoid shape
trianglet triangle triangletshape;
IMPLEMENT THIS
return ;
Initializes a rectangle shape
void rectangleconstructrectanglet shape, const char name,
double width, double length
IMPLEMENT THIS
Initializes a triangle shape
void triangleconstructtrianglet shape, const char name,
double length
IMPLEMENT THIS
Compares the area of shape with shape
Returns if the area of shape is less than the area of
shape
Returns if the area of shape is greater than the area of
shape
Returns if the area of shape is equal to the area of shape
int comparebyareashapet shape shapet shape
IMPLEMENT THIS
return ;
Compares the perimeter of shape with shape
Returns if the perimeter of shape is less than the
perimeter of shape
Returns if the perimeter of shape is greater than the
perimeter of shape
Returns if the perimeter of shape is equal to the perimeter
of shape
int comparebyperimetershapet shape shapet shape
IMPLEMENT THIS
return ;
Linked list functions
Initializes a singly linked list
If compare is NULL, the list is unsorted and new nodes are
inserted at the head of the list
If compare is not NULL, the list is sorted in increasing order
based on the comparison function
void linkedlistinitlinkedlistt list, comparefn compare
IMPLEMENT THIS
Inserts a node into the linked list based on the list
comparison function
void linkedlistinsertlinkedlistt list, linkedlistnodet
node
IMPLEMENT THIS
Removes all nodes from the linked list containing the given
shape
void linkedlistremovelinkedlistt list, shapet shape
IMPLEMENT THIS
Tree iterator functions
Initializes an iterator to the beginning of a tree ie
first inorder node
void treeiteratorbegintreeiteratort iter, treenodet
root
IMPLEMENT THIS
Updates an iterator to move to the next inorder node in the
tree if possible
Moving past the last inorder node in the tree results in the
iterator reaching a NULL state representing the end of the tree
void treeiteratornexttreeiteratort iter
IMPLEMENT THIS
Returns true if iterator is at the end of the tree or false
otherwise
The end of the tree is the position after the last inorder
node in the tree ie NULL state from treeiteratornext
bool treeiteratoratendtreeiteratort iter
IMPLEMENT THIS
return false;
Returns the current node that the iterator references or NULL
if the iterator is at the end of the tree
treenodet treeiteratorgetnodetreeiteratort iter
IMPLEMENT THIS
return NULL;
Returns the current shape that the iterator references or NULL
if the iterator is at the end of the tree
shapet treeiteratorgetshapetreeiteratort iter
IMPLEMENT THIS
return NULL;
Tree analysis functions
Returns the maximum, minimum, and average area of shapes in
the tree
An empty tree should not modify the maximum, minimum, or
average
void maxminavgareatreenodet root, double max, double
min, double avg
IMPLEMENT THIS
Executes the func function for each node in the tree inorder
The function takes in an input data and returns an output
data, which is used as input to the next call to the function
The initial input data is provided as a parameter to foreach,
and foreach returns the final output data
For example, if there are three nodes, foreach should behave
like: return funcnode funcnode funcnode data
double foreachtreenodet root, foreachfn func, double data
IMPLEMENT THIS
return ;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started