// Minor 10
// Spring 2013
#include "minor10.h"
struct info startList( char *readt, char *readn );
void addInfo( struct info **head, char *readt, char *readn );
void newList( struct info **head, char *readt, char *readn );
char takeInfo( struct info **head, char *nTime );
int main( void )
{
char time[5];
char nTime[5];
char name[15];
char command[7];
struct info *head;
scanf( "%s", time );
scanf( "%s", command ); // Understood enqueue for
scanf( "%s", name ); // first command
head = (struct info*)malloc(sizeof(struct info));
*head = startList( time, name );
printf( "%s entered the Queue at %s\n", name, time );
while( scanf( "%s", time ) != EOF )
{
scanf( "%s", command );
if( strcmp( command, "enqueue" ) == 0 )
{
scanf( "%s", name );
newList( &head, time, name );
printf( "%s entered the Queue at %s\n", name, time );
}
else if( strcmp( command, "dequeue" ) == 0 )
{
*nTime = takeInfo( &head, nTime );
printf( "%s, who entered the Queue at %s", name, nTime );
printf( ", dequeued, receiving service at %s\n", time );
}
}
return 0;
}
struct info startList( char *readt, char *readn )
{
struct info *head;
head = malloc(sizeof(struct info));
head->time = readt;
head->name = readn;
head->next = NULL;
return *head;
}
void newList(struct info **head, char *readt, char *readn )
{
struct info* current;
current = *head;
while( current != NULL )
current= current->next;
addInfo( ¤t, readt, readn );
}
void addInfo( struct info **head, char *readt, char *readn )
{
struct info* newInfo = malloc(sizeof(struct info));
newInfo->time = readt;
newInfo->name = readn;
newInfo->next = head;
*head = newInfo;
}
char takeInfo( struct info **head, char *nTime )
{
struct info* take;
*take = **head;
nTime = take->time;
take = take->next;
return *nTime;
}