简体   繁体   中英

How can I better implement this queue using c?

I need to create a queue for a car service management system. The organisation offers two service types "Normal" and "Urgent".Priority is given to the clients who choose the urgent option and thus, are served earlier than the normal clients. This is my code, please feel free to ask any questions and I ask that you take this question with an open mind. Thanks in adv ''' '

struct node *normal= NULL;
struct node *urgent= NULL;

void queueRegistration()
{
    /*Print Menu to user */
    char urgency;




    int choice;

    char *service;
    char *serviceType;

    /*Queue cutting menu*/

    system("cls");
    gotoxy(50,1);
    printf("================================");
    gotoxy(50, 2);
    printf("QUEUE REGISTRATION");
    gotoxy(50, 3);
    printf("================================\n");
    gotoxy(50, 4);
    printf("We offer urgent and Normal prices, service prices depend on 
    the urgency\n");
    gotoxy(50, 6);
    printf("1.Normal price\n");
    gotoxy(50, 7);
    printf("2.Urgent price\n");
    gotoxy(50, 8);
    printf("Pick an option number from the list[1 or 2]: \n");
    gotoxy(50, 9);
    scanf("%d",& choice);

    time_t t = time(NULL);
    struct tm *tm = localtime(&t);
    int s[64];
    assert(strftime(s, sizeof(s), "%c", tm));
    int DATE ;
    DATE = s;
    return 0;

    if(choice==1)
    {
    struct node *temp,*ptr;
    temp=(struct node *)malloc(sizeof(struct node));
    if(temp==NULL){
    printf("\nOut of Memory Space:\n");
    return;
    }
    printf("\nEnter Name:\t" );
    scanf("%s",&temp->name );
    printf("\nEnter Car Number Plate:\t" );
    scanf("%s",&temp->plateNumber );

    temp->next =NULL;
    if(normal==NULL)
    {
                  normal=temp;
    }
    else
    {
    ptr=normal;
    while(ptr->next !=NULL){
    ptr=ptr->next ;
    }
    ptr->next =temp;
    }

    }
    else if(choice==2)
    {
    struct node *temp,*ptr;
    temp=(struct node *)malloc(sizeof(struct node));
    if(temp==NULL){
    printf("\nOut of Memory Space:\n");
    return;}

    printf("\nEnter Name:\t" );
    scanf("%s",&temp->name );

    printf("\nEnter Car Number Plate:\t" );
    scanf("%s",&temp->plateNumber );

    temp->next =NULL;
    if(urgent==NULL)
    {
    urgent=temp;}

    else{
    ptr=urgent;
    while(ptr->next !=NULL){
    ptr=ptr->next ;
    }
    ptr->next =temp;
    }
    }
    

} ' '''

I need to create a queue for a car service management system. The organisation offers two service types "Normal" and "Urgent".Priority is given to the clients who choose the urgent option and thus, are served earlier than the normal clients. This is my code, please feel free to ask any questions and I ask that you take this question with an open mind. Thanks in adv ''' '

struct node *normal= NULL;
struct node *urgent= NULL;

void queueRegistration()
{
    /*Print Menu to user */
    char urgency;




    int choice;

    char *service;
    char *serviceType;

    /*Queue cutting menu*/

    system("cls");
    gotoxy(50,1);
    printf("================================");
    gotoxy(50, 2);
    printf("QUEUE REGISTRATION");
    gotoxy(50, 3);
    printf("================================\n");
    gotoxy(50, 4);
    printf("We offer urgent and Normal prices, service prices depend on 
    the urgency\n");
    gotoxy(50, 6);
    printf("1.Normal price\n");
    gotoxy(50, 7);
    printf("2.Urgent price\n");
    gotoxy(50, 8);
    printf("Pick an option number from the list[1 or 2]: \n");
    gotoxy(50, 9);
    scanf("%d",& choice);

    time_t t = time(NULL);
    struct tm *tm = localtime(&t);
    int s[64];
    assert(strftime(s, sizeof(s), "%c", tm));
    int DATE ;
    DATE = s;
    return 0;

    if(choice==1)
    {
    struct node *temp,*ptr;
    temp=(struct node *)malloc(sizeof(struct node));
    if(temp==NULL){
    printf("\nOut of Memory Space:\n");
    return;
    }
    printf("\nEnter Name:\t" );
    scanf("%s",&temp->name );
    printf("\nEnter Car Number Plate:\t" );
    scanf("%s",&temp->plateNumber );

    temp->next =NULL;
    if(normal==NULL)
    {
                  normal=temp;
    }
    else
    {
    ptr=normal;
    while(ptr->next !=NULL){
    ptr=ptr->next ;
    }
    ptr->next =temp;
    }

    }
    else if(choice==2)
    {
    struct node *temp,*ptr;
    temp=(struct node *)malloc(sizeof(struct node));
    if(temp==NULL){
    printf("\nOut of Memory Space:\n");
    return;}

    printf("\nEnter Name:\t" );
    scanf("%s",&temp->name );

    printf("\nEnter Car Number Plate:\t" );
    scanf("%s",&temp->plateNumber );

    temp->next =NULL;
    if(urgent==NULL)
    {
    urgent=temp;}

    else{
    ptr=urgent;
    while(ptr->next !=NULL){
    ptr=ptr->next ;
    }
    ptr->next =temp;
    }
    }
    

} ' '''

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM