Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In this lab you will use structure point as designed in the example above. Your

ID: 3733694 • Letter: I

Question

In this lab you will use structure point as designed in the example above. Your task is to design a simple linked list and an interactive menu. The menu would have the following:

1. Add a point at the END of the list.

2. Add a point at the BEGINNING of the list.

3. Is the list empty?

4. Erase all points from the list (reset)

. 5. Display the list.

6. Save the list to a sequential file (reset/replace file contents)

7. Read the list back from a sequential file (reset/replace current memory content)

0. Exit Start by creating the self-referential structure described in the example above.

Then setup useful variables like: struct point *ptrFirst, *ptrLast; to represent pointers to the beginning and end of the list.

Remember to initialize your pointers to NULL. (include stdlib.h). Then design each of the functions required by the menu.

When designing these functions you need to draw the memory structures and carefully keep track of where each pointer is pointing and what values are in each memory location. Also remember that since you are using pointers to access structures, you need to use the arrow '->' operator to access the members of the structures

. Q.What does it mean to have an empty list? (A.check if the ptrFirst is NULL, since ptrFirst is designed to point to the first element in the list, and if so happens that the first element is NULL, then that means that there is no first element and consequently the list is empty).

#include #include

// DOCUMENT!!!!!! struct point { int x; int y; char label[21];

struct point *ptrNext; // self referential pointer };

int isEmptyList(struct point *ptrF);

void PrintList(struct point *ptrF);

void ResetList(struct point *ptrF, struct point *ptrL);

void AddToBeginning(struct point *ptrF, struct point *ptrL);

void AddToEnd(struct point *ptrF, struct point *ptrL);

void InputRecord(struct point *ptrNew); // used by Add to interactively get the values from the user struct point

*ptrFirst = NULL; struct point *ptrLast = NULL; void main() { // do the menu }

- Design the self referential structure, read and practice how to create and free individual nodes.

- Complete the requirements and all the functions as specified. Document EVERY function (purpose/input/output), and EVERY declaration (Variables and Arrays), and every structure definition.

Explanation / Answer

/******************************************************************************

Online C Compiler.
Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <stdio.h>

#include <stdlib.h>
#include<string.h>

struct point

{

int x;

int y;

char label[21];

struct point *ptrNext;

};

struct point* createNewPoint(int x, int y, char label[])

{

struct point* new_point = (struct point*) malloc(sizeof(struct point));

new_point->x = x;

new_point->y = y;

strcpy(new_point->label, label);

new_point->ptrNext = NULL;

return new_point;

}

void AddToBeginning(struct point** ptrHead, struct point *new_point)

{

*ptrHead = new_point;

}

void AddToEnd(struct point** ptrHead, struct point *new_point)

{
struct point *temp;
if (*ptrHead == NULL) {

*ptrHead = new_point;

return;

}

temp = *ptrHead;

while (temp->ptrNext != NULL)

temp = temp->ptrNext;

temp->ptrNext = new_point;

}


void PrintList(struct point *ptrHead)

{

printf("x y label ");

while (ptrHead != NULL)

{

printf("%d %d %s ", ptrHead->x, ptrHead->y, ptrHead->label);

ptrHead = ptrHead->ptrNext;

}

}

int isEmptyList(struct point *ptrHead)

{

if (ptrHead == NULL)

return 1;

return 0;

}

int main()

{

struct point* ptrHead = NULL;

int x, y, input;

char label[21];

int exit = 0;

do {

printf("Enter any task from the below menu: ");

printf("1. Add a point at the END of the list. ");

printf("2. Add a point at the BEGINNING of the list. ");

printf("3. Is the list empty? ");

printf("4. Erase all points from the list (reset) ");

printf("5. Display the list. ");

printf("6. Save the list to a sequential file (reset/replace file contents) ");

printf("7. Read the list back from a sequential file (reset/replace current memory content) ");

printf("0. Exit Start by creating the self-referential structure described in the example above. ");

scanf("%d", &input);

switch(input) {

case 1: printf("Enter data x, y and label: ");

scanf("%d%d%s", &x, &y, label);

struct point *new_point = createNewPoint(x, y, label);

AddToEnd(&ptrHead, new_point);

break;

case 2: printf("Enter data x, y and label: ");

scanf("%d%d%s", &x, &y, label);

new_point = createNewPoint(x, y, label);

AddToBeginning(&ptrHead, new_point);

break;

case 3: if (isEmptyList(ptrHead))

printf("Yes, it is empty ");

else

printf("List is not empty ");

break;

case 4: /* TODO ResetList(&ptrHead); */ break;

case 5: PrintList(ptrHead); break;

case 6: /* TODO saveList(ptrHead); */ break;

case 7: /* TODO readBackList(ptrHead); */ break;

case 8: exit = 1; break;

}

} while(exit == 0);

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote