Assignment #3


Write a C program called as3.c to simulate a bus stop using queues implemented by linked lists (Do NOT change this file.). Your main program counts total number of passengers, keeps track of total waiting time and computes the average waiting time for a bus by calling either passenger or bus function according to input data. The input has 3 data on each line. Te first data indicates either passenger(s) (0) or a bus (1) arrives. The 2nd data is the arrival time (in order) and the 3rd one indicates either total number of passengers arrived or number of seats available in a bus. You must use an item structure which has 2 fields:

            int time; // stores either passenger or bus arrival time

            int count; // stores number of passengers or number of seats available in bus

to store the input for either passenger(s) or a bus such as

typedef struct {

   int time;

   int count;

} itemtype;

The node in the linked list uses (Do NOT put the following 5 lines into your program since they are in queue.h already)

struct node {

   int info; // stores time information

   struct node *next;

};

typedef struct node node;

 

In order to call the functions bus and passenger, you need to initialize head and tail in main function by

node  *head=NULL, *tail=NULL;

 

Specification:

  1. A function passenger uses the item structure (from main) to call enqueue function to put each passenger into a queue, such as

void passenger (node **ptrhead, node **ptrtail, itemtype *itemptr); // gets itemptr from main program

void enqueue (node **ptrhead, node **prttail, int item);

  1. A function bus uses the item structure to call dequeue function and keep returns passengers’ total waiting time, such as

double bus (node **ptrhead, node **ptrtail, itemtype *itemptr); // gets itemptr from main program  and returns total waiting time up to the bus arrival

int dequeue (node **ptrhead, node **ptrtail); // returns time information in the list

 

Your output should be the same as the result file.

 

Note:

 

(You can

cp  /home/cshing/public_html/310/Assignment/as3.c  .

cp  /home/cshing/public_html/310/Assignment/as3_data.txt  .

cp  /home/cshing/public_html/310/Assignment/queue.c  .

cp  /home/cshing/public_html/310/Assignment/queue.h  .

cp  /home/cshing/public_html/310/Assignment/Makefile  .

 

Put in your as3.c  the line (See testas3.c)

#include “queue.h” under

#include <stdio.h>

 

make

make run

make clean

Submit your as3.c file.

FAQ

Instructions for Submitting Your Work