Hi i have a taxi queue program with a double linked list with a pointer at thre front and end of the queue
the problem im having is when ever i enter a taxi wether it be the 2nd or 3rd or 10th taxi in the list it will change all the other taxi registration numbers in the list to the same registration
any help would be greatful
removing taxis from the queue works perfect and this setback is limiting from building the rest of the program
Code:
/* Declare a taxi structure with pointers for suitable for a linear double */
/* linked list. */
struct TAXI_STRUCT
{
char* pszRegistrationNo;
TAXI_STRUCT* pNext;
TAXI_STRUCT* pLast;
};
/* Declare the pointers to track the start and end of the list. */
TAXI_STRUCT* pFirstTaxi = NULL;
TAXI_STRUCT* pLastTaxi = NULL;
/* Function to add a taxi to the list. */
void AddLastTaxi(char* pszRegistrationNo)
{
TAXI_STRUCT* pNewTaxi = new TAXI_STRUCT;
pNewTaxi->pszRegistrationNo = pszRegistrationNo;
if (pFirstTaxi == NULL && pLastTaxi == NULL) /* If queue has nothing in it */
{
pNewTaxi->pLast = NULL;
pNewTaxi->pNext = NULL;
pFirstTaxi = pNewTaxi;
pLastTaxi = pNewTaxi;
}
else
{
pNewTaxi->pLast = NULL;
pNewTaxi->pNext = pLastTaxi;
pLastTaxi->pLast = pNewTaxi;
pLastTaxi = pNewTaxi;
}
}
Menu for the program
Code:
int main(int argc, char* argv[])
{
int menu = 0;
char RegistrationNo[] = "";
/* Loop for Menu */
while ( menu != 8 )
{
/* Menu for the Queue Displayed to the User */
printf("-------------------------------\n");
printf("Please Select an option from the menu.\n");
printf("1. arrive: Add a taxi to the end of the queue.\n");
printf("2. leave: Remove the first taxi in the queue.\n");
printf("3. search: Search for a taxi within the queue.\n");
printf("4. print: Print the Taxi queue.\n");
printf("5. front: Display the taxi at the front of the queue.\n");
printf("6. back: Display 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("%d",&menu); /* Read Input for menu from the User */
switch (menu) /* Menu System for the Taxi Rank */
{
case 1:
/* Enter Taxi Registration Number to the Queue */
printf("Please enter the Taxi Registration Number that has joined the queue.\n");
scanf("%s", RegistrationNo);
AddLastTaxi(RegistrationNo); /* Add a Taxi to the End of the Queue*/
printf("The Following Taxi has joined the queue: %s \n", RegistrationNo);
break;
case 2: /* Remove the First Taxi from the Queue */
printf("Removing %s\n", RemoveFirstTaxi());
break;
case 3: /* Search list for a taxi registration Number */
break;
case 4: /* Print the Taxi Queue in the Current State */
PrintTaxiQueue();
break;
case 5: /* Which Taxi is at the Front of the Queue */
break;
case 6: /* Which Taxi is at the Back of the Queue */
break;
case 7: /* Display if the queue is Empty or Not */
break;
case 8: /* Exit the program */
break;
}
}
printf("Thank you for using the program Goodbye....");
getch();
}