Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is what i have so far i want to fix the Function: Enlist, and Function: Delist /* * File: mylinkedlist.c * YOUR NAME ...

This is what i have so far i want to fix the Function: Enlist, and Function: Delist /* * File: mylinkedlist.c * YOUR NAME ... * YOU NEED TO IMPLEMENT THE FUNCTIONS here * .... */ #include  #include  #include "mylinkedlist.h" /* * Function: NewStudentCell * Usage: student_cell_T *element; * element = NewStudentCell(int id, double gpa, char *name); * -------------------------- * This function allocates space for a student cell and intilize its fileds */ student_cell_T *NewStudentCell(int id, double gpa, char *name) { student_cell_T *element; element = (student_cell_T *) malloc( sizeof(student_cell_T) ); if( !element){ fprintf(stderr,"NewStudentCell cannot allocate memory "); return NULL; } element->id = id; element->gpa = gpa; element->name = name; return element; } /* * Function: NewLinkedList * Usage: linked_list_T *list; * list = NewLinkedList(); * -------------------------- * This function allocates and returns an empty linked list. */ linked_list_T *NewLinkedList(void) { linked_list_T *list; list = (linked_list_T *) malloc( sizeof(linked_list_T) ); if( !list){ fprintf(stderr,"NewLinkedList cannot allocate memory "); return NULL; } list->head = NULL; list->tail = NULL; return list; } /* * Function: FreeLinkedList * Usage: FreeLinkedList(list); * ------------------------ * This function frees the storage associated with list. */ void FreeLinkedList(linked_list_T *list) { /*if (!LinkedListIsEmpty(list)) free(Delist(list)); FreeLinkedList(list);*/ //struct node* temp; while(!LinkedListIsEmpty(list)) { free(Delist(list)); } } /* * Function: Enlist * Usage: Enlist(list, element); * ------------------------------- * This function adds a student cell pointed by element to the end of the list. */ void Enlist(linked_list_T *list, student_cell_T *element) { // if null then the cell inserted will be the head and the tail since it is the only element there if (list -> tail == NULL) { list -> head = list -> tail = element; return; } (list -> tail) -> next = element; // points tail to next node (list -> tail) = (list -> tail) -> next; // asigning the tail to the last node } /* * Function: Delist * Usage: element = Delist(list); * -------------------------------- * This function removes the student cell at the head of the list * and returns its address to the caller (client). If the list is empty, Delist * prints an Error with an appropriate message and returns NULL. */ student_cell_T *Delist(linked_list_T *list) { //check if the list is empty if(list -> head == NULL || list -> tail == NULL){ list->head = list->tail = list; } /* if(list ->head == NULL){ return NULL; } else{ list ->head = list -> head -> next; return list ->head;*/ } /* * Functions: LinkedListIsEmpty, LinkedListIsFull * Usage: if (LinkedListIsEmpty(list)) . . . * if (LinkedListIsFull(list)) . . . * ------------------------------------- * These functions test whether the list is empty or full. */ int LinkedListIsEmpty(linked_list_T *list) { return (list->head == NULL || list->tail == NULL); } int LinkedListIsFull(linked_list_T *list) { return 0; // because we have linked list } /* * Function: LinkedListLength * Usage: n = LinkedListLength(list); * ------------------------------ * This function returns the number of elements in the list. */ int LinkedListLength(linked_list_T *list) { int length = 0; for(student_cell_T*recursive=list -> head; recursive != NULL; recursive=recursive->next) length += 1; return length; } /* * Function: GetLinkedListElement * Usage: element = GetLinkedListElement(list, index); * ----------------------------------------------- * This function returns the element at the specified index in the * list, where the head of the list is defined as index 0. For * example, calling GetLinkedListElement(list, 0) returns the initial * element from the list without removing it. If the caller tries * to select an element that is out of range, GetLinkedListElement prints * Error and returns NULL. Note: This function is not a fundamental list operation * and is instead provided mainly to facilitate debugging. */ student_cell_T *GetLinkedListElement(linked_list_T *list, int index) { student_cell_T* node = list -> head; for (int i = 0; i < index && node!= NULL; i++) { node = node -> next; } return node; } /* OTHER FUNCTIONS YOU WOULD NEED.... * EXPORT THEM HERE, BUT IMPLMENT THEM in mylinkedlist.c */ 

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_2

Step: 3

blur-text-image_3

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

More Books

Students also viewed these Databases questions

Question

How does selection differ from recruitment ?

Answered: 1 week ago

Question

2. Employees and managers participate in development of the system.

Answered: 1 week ago