Question: typedef struct _coord { float x; float y; struct _coord *next; } coord; typedef struct { coord *head; char *name; } polygon; /* * Allocates

typedef struct _coord {

float x;

float y;

struct _coord *next;

} coord;

typedef struct {

coord *head;

char *name;

} polygon;

/*

* Allocates space for polygon struct, and for the name

* Copies the name into the polygon struct

* Returns a pointer to the new polygon.

*

* NOTE: use strlcpy instead of strcpy

*/

polygon *init_polygon(char *name){

//YOUR CODE HERE

return NULL;

}

/*

* Initializes a coordinate struct. Called by push(..)

* Allocates the struct

* Assigns x and y

* The next pointer is initializes to NULL

* Return a pointer to the newly-initialized struct.

*/

coord *init_coord(float x, float y) {

//YOUR CODE HERE

return NULL;

}

/*

* Returns the number of sides for the polygon.

* This is (roughly) equal to the number of nodes, with some boundary cases

* A polygon with no points has zero sides

* A polygon with one point has zero sides

* A polygon with two points has one side

* A polygon with three points has three sides (etc.)

*

* You may assume that p is never null.

*/

int polygon_sides(polygon *p) {

//YOUR CODE HERE

return -1;

}

/*

* Returns the pointer to the LAST element of the linked list.

* That is, the element that points to p->head

*

* If the list is empty, return NULL

*

* You may assume that p is never null.

*/

coord *find_last(polygon *p) {

//YOUR CODE HERE

return NULL;

}

/*

* Adds a new node to the list

*

* Treat this list like a stack, i.e,

* the new node should become the head

*

* Call init_coord to create the new node.

*

* Tip: call find_last(..) to help with insertion

*

* You may assume that p is never null.

*/

void push(polygon *p, float x, float y) {

//YOUR CODE HERE

return;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!