Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 4

/* CS211 Summer 2020 Project 3

TODO: Complete this comment with name, date, purpose.


Author: Bianca Atienza
Date: May 26 2020

*/

#include <stdio.h>
#include <stdlib.h>

#define TRUE 1
#define FALSE 0

int DebugMode; //global variable

/* TODO: create PointNode and Polygon data types using typedef */

// PointNode properties:
/*
int ID
struct pointNode* next
*/
typedef struct pointNode {
int ID;
struct pointNode* next;
} PointNode;

// Polygon properties:
/*
PointNode* points
int nPoints
int min, max
*/
typedef struct {
PointNode* points;
int nPoints;
int min, max;
} Polygon;

/* TODO: uncomment these function prototypes.


Functions appear below main, in the order listed here. */

int addVertexToPolygon( Polygon* polygon, int vertexID );


PointNode* findVertexInPolygon( Polygon polygon, int vertexID );
int size( Polygon polygon );
int isEmpty( Polygon polygon );
int removeVertexFromPolygon( Polygon* polygon );
void displayVertexIndices(Polygon * polygon);

int main(int argc, char const *argv[])


{
PointNode pointNode;
Polygon polygon;
int userVertices = pointNode.ID;
pointNode.ID = 0;
pointNode.next = NULL;
polygon.points = NULL;

//int vertexID;

/* TODO: Global variable DebugMode: if -d argument is given, additional


information should be printed out as the program runs. */
/* Look at lab 4 for help on this */
DebugMode = FALSE; //debug to check if code works, implement print statements
throughout
for (int i = 0; i < argc; i++)
{
if(strcmp(argv[i], "-d") == 0) {
DebugMode = TRUE;
if(DebugMode) {
printf("Debug Mode is enabled.");
}
}
}

/* TODO: Read data for the vertices comprising a Polygon (build a polygon) from
standard input */
/* Read data until a negative integer is read */
printf("Enter vertices: \n");
scanf("%d", &userVertices);
while(userVertices >= 0) {

addVertexToPolygon(&polygon, pointNode.ID);
printf("Enter vertices: \n");
scanf("%d", &userVertices);
}

/* TODO: Report the Polygon's number of vertices, the specific list of vertex
indecies,
and the minimum and maximum indices in the list.
*/
displayVertexIndices(&polygon);
// for(int i = 0; i < polygon.nPoints; polygon.nPoints++) {
//
// }
//printf("This polygon has %d vertices, with indices %d,", )
/* TODO: Read data for a second set of vertices, and for each vertex ID search
the Polygon's list of vertices,
if a matching vertex ID is found, report the address of the PointNode
where the ID was found.
*/
/* Read data until a negative integer is read */

/* TODO: Make sure you free any dynamically allocated memory before the program
ends.
Use Valgrind to check, because TAs will. */

return 0;

/* TODO: function definitions */


int addVertexToPolygon( Polygon* polygon, int vertexID ) {
PointNode * newNode = (PointNode *)malloc(sizeof(PointNode));
newNode->ID = vertexID;
newNode->next = NULL;
int returnVal = -1;
if(polygon->points == NULL) {
polygon->points = newNode;
printf("hi\n");
returnVal = 0;
}
else {
newNode->next = polygon->points;
polygon->points = newNode;
printf("hello\n");
returnVal = 0;
}
polygon->nPoints++;
printf("world\n");
return returnVal;
}

void displayVertexIndices(Polygon * polygon) {


PointNode* tempNode = polygon->points;
while(tempNode != NULL) {
printf("%d", tempNode->ID);
tempNode = tempNode->next;
}
}

//void toFindTheMax(Polygon * polygon) {


// int i = 0;
// while(polygon->points != NULL) {
// if(
// }
//}
/* Return 0 if the vertex ID is successfully added to the polygon, or -1 otherwise.
Add vertices to the head of the linked list.
*/

/*
PointNode* findVertexInPolygon( Polygon polygon, int vertexID );

Return the address of the PointNode in which the vertex ID was found.
If the vertex was not found, return NULL.
*/

/*
int size( Polygon polygon );

Return the number of vertices in the polygon.


*/

/*
int isEmpty( Polygon polygon );

Return 1 if the polygon contains no vertices, or 0 otherwise.


*/

/*
int removeVertexFromPolygon( Polygon* polygon );

Removes one vertex from the Polygon from the head of the linked list,
frees up memory associated with the PointNode.

Return the ID of the removed vertex if a vertex was successfully removed, or -1


otherwise.
*/

You might also like