/********************************************************** * Filename: linkedlist.h * * Author: Sue Evans * * Written: 5/1/08 * * Section: 201staff * * Email: bogar@cs.umbc.edu * * * * This file contains the structure definition of a node, * * and typedefs of the types NODE and NODEPTR. It also * * contains the function prototypes for the functions * * defined in linkedlist.c, which are the linked list * * implementation of a list abstract data type. * **********************************************************/ /************ Step 1 ***************/ #define NAMESIZE 20 /* NODEPTR is defined as an alias for * "struct node *" so it can be used * within the structure before it is * completely defined. */ typedef struct node * NODEPTR; /* The STUDENT node will store info * * about one student in a class. */ typedef struct student { char firstName[NAMESIZE]; char lastName[NAMESIZE]; int grade; int id; } STUDENT; /* A NODE is a structure that allows us to build a linked ** list since it has both a data portion and a NODEPTR as ** its members. The NODEPTR called next is known as the ** link. */ typedef struct node { STUDENT data; NODEPTR next; /* OR struct node *next; */ }NODE; /********************************************** * Function: CreateNode() * * Input: none * * Output: a pointer (of type NODEPTR) is * * returned that points to the * * newly allocated NODE. * * * * CreateNode() mallocs the memory necessary * * to hold a NODE. The members of the NODE's * * structure are initialized, and the beginning* * address of that memory is returned. * * * * NOTE: Exits if there is insufficient memory.* **********************************************/ NODEPTR CreateNode (void); /*********************************************** * Function: SetData * * Inputs: a pointer to a newly-created node * * a STUDENT structure which * * contains the data to be placed * * into that node * * Output: None * * * * The data member of the node pointed to by * * temp (temp->data) is populated with the * * values in the STUDENT structure called value * * in the function (the new student's info) * ***********************************************/ void SetData (NODEPTR temp, STUDENT value); /************************************************** * Function: Insert * * Inputs: the address of head which is of type * * NODEPTR * and is called headPtr * * within this function * * a pointer to the node to insert which * * is of type NODEPTR and is called * temp within the function * * Output: None * * * * The node 'temp' is added to the linked list at * * the end of the list. * **************************************************/ void Insert (NODEPTR* headPtr, NODEPTR temp); /************************************************* * Function: Delete * * Inputs: the address of the head (NODEPTR*) * * called headPtr in the function * * the id of student to be deleted (int)* * Output: If found, the student id of the * * student being deleted is returned * * If not found, a -1 is returned * * * * The list is traversed looking for a NODE that * * has as the student's id the value passed in as * * the target. If the id number that matches the * * target is found, the node is deleted from the * * list and the id number is returned. If the end* * of the list is reached without encountering the* * target id number, then -1 is returned * *************************************************/ int Delete (NODEPTR* headPtr, int target); /******************************************** * Function: IsEmpty * * Input: a pointer to the head of the * * linked list * * Output: returns 1 (true) if the list is * * empty; returns 0 (false) if * * the list is not empty * *********************************************/ int IsEmpty (NODEPTR head); /************************************************* * Function: PrintList * * Input: the head of the list * * Ouput: None * * * * Each data in each node in the list is printed * * according to the format specified * *************************************************/ void PrintList (NODEPTR head); /** !!! Don't forget to finish guarding this header file!!! **/