C 如何做公交车搜索功能

C 如何做公交车搜索功能,c,queue,C,Queue,我想在void search(void)上为这个程序做一个搜索功能 在该功能中,用户将在void-arrival(void)处输入信息 之后,我将扫描用户键入的字符,即bus\u num[20],程序将显示bus\u类型和容量。有人能教我怎么做吗 #include<conio.h> #include<stdio.h> #include<malloc.h> void arrive(void); void leave(void); void search(voi

我想在
void search(void)上为这个程序做一个搜索功能

在该功能中,用户将在
void-arrival(void)处输入信息

之后,我将扫描用户键入的字符,即
bus\u num[20]
,程序将显示
bus\u类型
容量
。有人能教我怎么做吗

#include<conio.h>
#include<stdio.h>
#include<malloc.h>

void arrive(void);
void leave(void);
void search(void);
void print(void);
void length(void);
int count;

struct bus{
    char bus_num[20];
    char bus_type[20];
    int capacity;
    struct bus *next;
}*ptr, *temp, *front, *rear;

void main()
{
    temp = NULL;
    rear = NULL;
    front = NULL;
    int option = 0;


    while (option != 6)
    {
        printf("\n\n*****menu driven*****\n");
        printf("\n\t 1.Arrive");
        printf("\n\t 2.Leave");
        printf("\n\t 3.Search");
        printf("\n\t 4.Print");
        printf("\n\t 5.Length");
        printf("\n\t 6.Exit");
        printf("\n\nSelect a option\n");
        scanf("%d", &option);
        switch (option)
        {
        case 1: arrive();break;
        case 2:leave();break;
        case 3:search();break;
        case 4:print();break;
        case 5:length();break;
        case 6:break;
        default: printf("\nInvalid Option\n");
        }
        getch();

    }
    getch();
}
void arrive(void)
{
    temp = (struct bus*)malloc(1 * sizeof(struct bus));
    printf("\nPlease Enter The Bus Registeration Number :");
    fflush(stdin);
    scanf("%s", &temp->bus_num);
    printf("\nPlease Enter The Bus Type :");
    fflush(stdin);
    scanf("%s", &temp->bus_type);
    printf("\nPlease Enter The Bus Capacity :");
    fflush(stdin);
    scanf("%d", &temp->capacity);
    count++;
    temp->next = NULL;
    if (front == NULL && rear == NULL)
    {
        front = rear = temp;
        return;
    }
    rear->next = temp;
    rear = rear->next;


}


void leave(void)
{
    if (front == NULL)
    {
        printf("\nThere are empty queue\n");
        return;
    }
    if (front == rear&&front != NULL)
    {
        ptr = front;
        printf("%s leaves the queue", &ptr->bus_num);
        front = rear = NULL;
        free(ptr);
    }
    else
    {
        ptr = front;
        printf("%s leaves", &ptr->bus_num);
        front = front->next;
        free(ptr);
    }
    count--;
}

void print(void)
{
    if (front == NULL&&rear == NULL)
    {
        printf("\nThere are no any Queue\n");
        return;
    }
    ptr = front;
    while (ptr != NULL)
    {
        printf("%s\t", ptr->bus_num);
        ptr = ptr->next;
    }
}

void length(void)
{
    printf("\n Queue size is %d", count);
}

void search(void)
{

}
#包括
#包括
#包括
无效到达(void);
无效休假(作废);
无效检索(void);
作废打印(作废);
空隙长度(空隙);
整数计数;
结构总线{
字符总线数[20];
字符总线_类型[20];
国际能力;
结构总线*下一步;
}*ptr,*温度,*前部,*后部;
void main()
{
温度=零;
后=空;
front=NULL;
int选项=0;
while(选项!=6)
{
printf(“\n\n*******菜单驱动******\n”);
printf(“\n\t 1.arrival”);
printf(“\n\t 2.离开”);
printf(“\n\t 3.Search”);
printf(“\n\t 4.Print”);
printf(“\n\t 5.长度”);
printf(“\n\t 6.Exit”);
printf(“\n\n选择一个选项”);
scanf(“%d”,选项(&O);
开关(选件)
{
案例1:到达;中断;
案例2:离开;休息;
案例3:搜索();中断;
案例4:打印();中断;
案例5:长度();断裂;
案例6:断裂;
默认值:printf(“\n无效选项\n”);
}
getch();
}
getch();
}
无效到达(无效)
{
temp=(结构总线*)malloc(1*sizeof(结构总线));
printf(“\n请输入总线注册号:”);
fflush(stdin);
scanf(“%s”,&temp->bus_num);
printf(“\n请输入总线类型:”);
fflush(stdin);
scanf(“%s”,&temp->bus_类型);
printf(“\n请输入总线容量:”);
fflush(stdin);
scanf(“%d”,&temp->capacity);
计数++;
temp->next=NULL;
如果(前==NULL和后==NULL)
{
前=后=温度;
返回;
}
后->下一步=温度;
后=后->下一步;
}
无效休假(作废)
{
if(front==NULL)
{
printf(“\n有空队列\n”);
返回;
}
如果(前==后和前!=空)
{
ptr=前部;
printf(“%s离开队列”,&ptr->bus_num);
前=后=零;
免费(ptr);
}
其他的
{
ptr=前部;
printf(“%s leaves”,&ptr->bus_num);
前=前->下一步;
免费(ptr);
}
计数--;
}
作废打印(作废)
{
如果(前==NULL和后==NULL)
{
printf(“\n没有任何队列\n”);
返回;
}
ptr=前部;
while(ptr!=NULL)
{
printf(“%s\t”,ptr->bus\u num);
ptr=ptr->next;
}
}
空隙长度(空隙)
{
printf(“\n队列大小为%d”,计数);
}
无效搜索(无效)
{
}