Code:
#include <stdio.h>
#include<stdlib.h>
#define MAX 6
int add (const int t_array[], int f, int r, int max, int added_t);
int leave (const int t_array[], int f, int r);
int linearSearch (const int t_array[], int key, int max);
int display (const int t_array[], int f, int r);
int displayFront (const int t_array[], int f);
int displayRear (const int t_array[], int r);
int emptyDisplay (const int t_array[], int f);
int main()
{
int taxi_array[MAX];
int menu = 0;
int rear = -1;
int front = -1;
int searchKey;
int taxi_element;
int addedTaxi;
// Loop for Menu
while ( menu <= 8 )
{
//Menu for User
printf("-------------------------------\n");
printf("Please Select an option from the menu.\n");
printf("1. arrive: Add a taxi to the rear of the queue.\n");
printf("2. leave: Remove the taxi at the front of the queue.\n");
printf("3. search: Search for a taxi within the queue.\n");
printf("4. print: Display the reg numbers of the taxis in the queue.\n");
printf("5. front: Display the reg number of the taxi at the front of the queue.\n");
printf("6. back: Display the reg number of the taxi at the back of the queue.\n");
printf("7. empty: Display if the queue is Empty or not.\n");
printf("8. exit: Exit the program.\n");
printf("-------------------------------\n");
scanf_s("%d",&menu);
switch (menu) // Menu System for the Taxi Queue
{
case 1:
//Enter Taxi Registration Number to the Queue
add(taxi_array, front, rear, MAX, addedTaxi);
printf("The Following Taxi has joined the queue: %s \n", taxi_array[rear]);
break;
case 2: // Remove the First Taxi from the Queue
printf("The taxi at the front of the queue will now be removed.\n");
leave(taxi_array, front, rear);
printf("The following taxi will be removed: %s \n", taxi_array[front]);
break;
case 3: // Search list for a taxi registration Number
printf( "Enter the reg of the taxi you want to find :\n" );
scanf_s( "%d", &searchKey );
taxi_element = linearSearch( taxi_array, searchKey, MAX );
if ( taxi_element != -1 ) {
printf( "Found reg in queue postion: %d\n", taxi_element );
}
else {
printf( "Value not found\n" );
}
return 0;
break;
case 4: // Print the Taxi Queue in the Current State
printf("This will now display all of the taxis. \n");
display(taxi_array, front, rear);
break;
case 5: // Which Taxi is at the Front of the Queue
printf("This will now display the taxi at the front of the queue.\n");
displayFront(taxi_array, front);
break;
case 6: // Which Taxi is at the Back of the Queue
printf("This will now display the taxi at the back of the queue.\n");
displayRear(taxi_array, rear);
break;
case 7: // Display if the queue is Empty or Not
printf("This will now show if the queue is empty or not. \n");
emptyDisplay(taxi_array, front);
break;
case 8: // Exit the program
exit(0);
break;
default:
break;
}
}
int add(const int taxi_array[], int front, int rear, int MAX, int addedTaxi)
{
if (rear==MAX-1)
printf("Taxi Rank Full\n");
}
else (front==-1){ //If queue is initially empty
front=0;
printf("Input the reg of the new taxi : ");
scanf_s("%d", &addedTaxi);
rear=rear+1;
taxi_array[rear] = addedTaxi;
}//End of add
int leave(const int taxi_array[], int front, int rear)
{
if (front == -1 || front > rear)
{
printf("Space in Queue\n");
}
else
{
printf("Taxi reg removed : %d\n", taxi_array[front]);
front=front+1;
}
}//End of Leave
int linearSearch(const int taxi_array[], int searchKey, int MAX)
{
int n;
for ( n = 0; n < max; ++n ) {
if ( taxi_array[ n ] == key ) {
return n;
}
}
return -1;
}//End of Search
int display(const int taxi_array[], int front, int rear)
{
int i;
if (front == -1)
printf("Queue is empty\n");
else
{
printf("Queue is :\n");
for(i=front;i<= rear;i++)
printf("%d ",taxi_array[i]);
printf("\n");
}
}//End of Display
int displayFront(const int taxi_array[], int front)
{
printf("%d ",taxi_array[front]);
}//End of displayFront
int displayRear(const int taxi_array[], int rear)
{
printf("%d ",taxi_array[rear]);
}//End of displayRear
int emptyDisplay(const int taxi_array[], int front)
{
int i;
if (front == -1)
printf("Queue is empty\n");
else
printf("Queue has taxis in it.\n");
}//End of Empty Display
errors: