I need help modifying this code that builds a queue to one that builds a stack
Code:
/* ========================= MakeList () ============================ */
/* Builds a linked list of names based on data from a file. This */
/* functions calls MakeNode () and LoadNode () program functions. */
/* It returns a pointer to the start of the list it built. */
/* ==================================================================== */
struct record * MakeList ( void )
{
FILE * fp; /* output file pointer */
struct record * start = NULL, /* @ of first node in list */
* current, /* @ of where we are at any pt */
* new; /* some pointers to use later */
char buffer [ 81 ]; /* space for string from file */
/* check output file success */
if ( ( fp = fopen ( FILENAME, "r" ) ) == NULL ) {
printf ( "MAKELIST: Unable to open input file %s!\n", FILENAME );
exit ( 1 );
}
fgets ( buffer, 81, fp ); /* do a 'priming read' */
while ( ! feof ( fp ) ) { /* read & process all file contents */
new = MakeNode ();
if ( start == NULL )
start = current = new; /* start a new list */
else {
current->next = new; /* move pointer to new node */
current = current->next;
}
LoadNode ( current, buffer );
fgets ( buffer, 81, fp ); /* get rady for next test */
}
fclose ( fp );
return start;
} /* -------------------- end MakeList () -------------------------- */
/* ========================= LoadNode () ============================ */
/* Loads a list node with data from a string passed in. Calls no */
/* program other functions. */
/* Parms: locn := ptr to list node to be filled */
/* str := holds source data to be separated and loaded */
/* ==================================================================== */
void LoadNode ( struct record * locn, char str [] )
{
sscanf ( str, "%s %s %d %f", locn->first, locn->last, &locn->age,
&locn->average );
return;
} /* -------------------- end LoadNode () -------------------------- */
/* ========================= MakeNode () ============================ */
/* Creates a new node of record type and returns pointer to it. */
/* Calls no other program functions. */
/* ==================================================================== */
struct record * MakeNode ( void )
{
struct record * newptr; /* a local pointer */
/* dynamicaly allocate some storage and initialize */
newptr = ( struct record * ) calloc ( 1, sizeof ( struct record ) );
newptr->next = NULL;
return newptr; /* send address of new node back */
} /* -------------------- end MakeNode () -------------------------- */