Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Managing Your Information How To Design And Create A Textual Database On Your Microcomputer

Authors: Tenopir, Carol, Lundeen, Gerald

1st Edition

1555700233, 9781555700232

More Books

Students also viewed these Databases questions

Question

3. How effective is the team?

Answered: 1 week ago

Question

2. What are your challenges in the creative process?

Answered: 1 week ago