📄 menu3.cpp
字号:
tmp=tmp->next;
}
return head;
}
/*-----------------------------------------------------------------*
*函数: sort() *
*参数: 整型,表结构数组 *
*作用: 排序成绩记录 *
*返回: 无 *
*-----------------------------------------------------------------*/
void sort(int table,sys sort_grade[100])
{
int i,j,mid,low,high;
sys temp;
if(table==9)
{
for(i=0;sort_grade[i].schead!=NULL;i++)
{
temp=sort_grade[i];
low=0;high=i;
//查找插入点
do
{
mid=(low+high)/2;
if(sort_grade[mid].schead->SC_GRADE>temp.schead->SC_GRADE)
{
low=mid+1;//步进
}
else
{
high=mid-1;//步退
}
}while(low<=high);
for(j=i;j>low;j--)
{
sort_grade[j]=sort_grade[j-1];
}
sort_grade[low]=temp;
}
}
if(table==11)
{
for(i=0;sort_grade[i].joinactivityhead!=NULL;i++)
{
temp=sort_grade[i];
low=0;high=i;
//查找插入点
do
{
mid=(low+high)/2;
if(sort_grade[mid].joinactivityhead->J_GRADE<temp.joinactivityhead->J_GRADE)
{
low=mid+1;//步进
}
else
{
high=mid-1;//步退
}
}while(low<=high);
for(j=i;j>low;j--)
{
sort_grade[j]=sort_grade[j-1];
}
sort_grade[low]=temp;
}
}
}
QUEUE *createqueue()
//创建窗口队列
{
QUEUE *queuehead;
queuehead=(QUEUE *)malloc(sizeof(QUEUE));
STUINFO *point;
point=(STUINFO *)malloc(sizeof(STUINFO));
point->next=NULL; //结点及队列初始化
queuehead->rear=point;
queuehead->front=point;
queuehead->nodeno=0;
return queuehead;
}
int selectqueue(QUEUE *a[],int i)
//参数为窗口头数组名及窗口个数,返回最少人数窗口,无窗口返回0
{
int temp=a[0]->nodeno,k=0;
if(a==NULL)
return 0;
for(int j=1;j<i;j++)
{
if(temp>a[j]->nodeno)
{
temp=a[j]->nodeno;
k=j;
}
}
return k;
}
int isempty(QUEUE *q)
//判断链队列q是否为空,为空返回1,否则返回0
{
if (q->front==q->rear)
return(1);
else
return(0);
}
STUINFO *front(QUEUE *q)
//返回链队列q的队头元素的地址
{
if (isempty(q))
{
printf("queue is empty\n");
return NULL;
}
else
return(q->front->next);
}
int dequeue(QUEUE *q)
//将链队列q的队头元素出队列,成功返回1,失败返回0
{ STUINFO *s;
if (isempty(q))
{
printf("queue is empty\n");
return 0;
}
else
{
s=q->front;
q->front=q->front->next;
q->nodeno--;
free(s);
return 1;
}
}
TM addtime(TM x,int y)
//处理时间的加法函数 ,y限制为分钟数
{
int temp;
x.tm_min=x.tm_min+y;
temp=x.tm_min/60;
x.tm_min=x.tm_min%60;
x.tm_hour=x.tm_hour+temp;
return x;
}
int gethour()
{
int temp;
scanf("%d",&temp);
while(temp<=0||temp>=24)
{
printf("时间不合法,请重新输入!\n");
scanf("%d",&temp);
}
return temp;
}
int getmin()
{
int temp;
scanf("%d",&temp);
while(temp<=0||temp>=60)
{
printf("时间不合法,请重新输入!\n");
scanf("%d",&temp);
}
return temp;
}
TM getwaitime(TM arrtime,TM logtime)
//获取等待时间
{
TM restime;
restime.tm_hour=logtime.tm_hour-arrtime.tm_hour;
if(logtime.tm_min<arrtime.tm_min)
{
restime.tm_hour-=1;
logtime.tm_min+=60;
}
restime.tm_min=logtime.tm_min-arrtime.tm_min;
return restime;
}
int cmptime(TM x,TM y)
//对两个时间进行比较,如果左边大于右边返回1,否则返回0
{
if(x.tm_hour>y.tm_hour)
return 1;
else if(x.tm_hour<y.tm_hour)
return 0;
else if(x.tm_min>y.tm_min)
return 1;
else return 0;
}
void dequeueall(QUEUE *a[],TM y,int i,int j)
{
int k;
extern int registtime;
extern TRANSA action[MAXSIZE];
extern int actnum;
for(k=0;k<j;k++)
{
if(!isempty(a[k])&&!cmptime(a[k]->front->next->logtime,y))
{
action[actnum].acttype=2;
action[actnum].haptime=a[k]->front->next->logtime;
strcpy(action[actnum].obj,a[k]->front->next->SNO);
action[actnum].num=k+1;
action[actnum].nodeno=a[k]->nodeno-1;
action[actnum].waitime=a[k]->front->next->waitime;
actnum++;
dequeue(a[k]);
}
}
}
int enqueue(QUEUE *a[],int i,int j,STUINFO x)
//将元素x放入链队列q的队尾,成功返回1,失败返回0
{
QUEUE *q;
q=a[i];
extern int registtime;
extern TRANSA action[MAXSIZE];
extern int actnum;
dequeueall(a,x.arrtime,i,j); //将所有此时应该出队的节点出队并保留事件
if(isempty(q))
{
if((q->rear->next=(STUINFO *)malloc(sizeof(STUINFO)))==0)
return 0;
q->rear=q->rear->next;
strcpy(q->rear->SNO,x.SNO);
q->rear->arrtime=x.arrtime;
q->rear->winnum=i+1;
q->rear->next=NULL;
q->rear->logtime=addtime(q->rear->arrtime,registtime);
q->rear->waitime.tm_hour=0;
q->rear->waitime.tm_min=registtime;
q->nodeno++;
action[actnum].acttype=1;
action[actnum].haptime=x.arrtime;
strcpy(action[actnum].obj,x.SNO);
action[actnum].num=i+1;
action[actnum].nodeno=q->nodeno;
actnum++;
}
else
{
if((q->rear->next=(STUINFO *)malloc(sizeof(STUINFO)))==0)
return 0;
q->rear->next->logtime=addtime(q->rear->logtime,registtime);
q->rear=q->rear->next;
strcpy(q->rear->SNO,x.SNO);
q->rear->arrtime=x.arrtime;
q->rear->winnum=i+1;
q->rear->next=NULL;
q->rear->waitime=getwaitime(q->rear->arrtime,q->rear->logtime);
q->nodeno++;
action[actnum].acttype=1;
action[actnum].haptime=x.arrtime;
strcpy(action[actnum].obj,x.SNO);
action[actnum].num=i+1;
action[actnum].nodeno=q->nodeno;
actnum++;
}
return 1;
}
int setnull(QUEUE *a[],int k)
//初始化队列
{
int i=0;
extern int registtime;
extern TRANSA action[MAXSIZE];
extern int actnum;
while(!isempty(a[k]))
{
action[actnum].acttype=2;
action[actnum].haptime=a[k]->front->next->logtime;
strcpy(action[actnum].obj,a[k]->front->next->SNO);
action[actnum].num=k+1;
action[actnum].waitime=a[k]->front->next->waitime;
action[actnum].nodeno=a[k]->nodeno-1;
actnum++;
dequeue(a[k]);
}
i=1;
return i;
}
void swap()
//将事件按时间进行排序
{
int i,j,swaped;
TRANSA temp;
extern int registtime;
extern TRANSA action[MAXSIZE];
extern int actnum;
for(i=1;i<actnum;i++)
{
swaped=true;
for(j=0;j<actnum-i-1;j++)
if(cmptime(action[j].haptime,action[j+1].haptime)==1)
{
temp=action[j+1];
action[j+1]=action[j];
action[j]=temp;
swaped=0;
}
if(swaped) break;
}
}
int registmenu(sys *all)
{
STUINFO temp_node,*head,*headpoint;
int i,j,flag_en,k,temp,temp6,registed=0;
QUEUE *array[10];
TM T;
extern int registtime;
extern TRANSA action[MAXSIZE];
extern int actnum;
for(i=0;i<5;i++) //初始化所有窗口
array[i]=NULL;
printf("\n请输入窗口个数(窗口个数小于10)\n");
scanf("%d",&i);
printf("请选择注册时间(单位:分)\n");
registtime=Force();
for(k=0;k<i;k++) //创建相应个数窗口
{
array[k]=createqueue();
}
headpoint=transport(all);
for(;;)
{
system("cls");
printf("〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓\n");
printf(" 新生报到 \n");
printf("1.寻找人数最少窗口\n");
printf("2.开始排队注册\n");
printf("3.显示当天报名情况\n");
printf("4.查找某时刻已发生事件状态\n");
printf("5.初始化系统\n");
printf("0.退出系统\n");
printf("〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓\n");
printf("请输入您选择的操作:\n");
j=Force();
while(j<0||j>5)
{
printf("没有相应的选项,请重新输入!\n");
j=Force();
}
switch(j)
{
case 1:
temp=selectqueue(array,i);
printf("请到第%d号窗口排队!\n",temp+1);
system("pause");
break;
case 2:
actnum=1; //1,2句为防止重复按2
registed=0;
head=headpoint->next;
while(head->next!=NULL)
{
temp=selectqueue(array,i);
strcpy(temp_node.SNO,head->SNO);
temp_node.arrtime.tm_hour=head->arrtime.tm_hour;
temp_node.arrtime.tm_min=head->arrtime.tm_min;
flag_en=enqueue(array,temp,i,temp_node);
if(flag_en==1)
printf("enqueue succeeded!\n");
else printf("enqueue failed!\n");
head=head->next;
}
for(temp6=0;temp6<i;temp6++)
setnull(array,temp6);
registed=1;
getch();
break;
case 3:
if(registed==0)
{
printf("还未开始报名注册,请先选择报名注册!\n");
break;
}
swap();
for(temp6=1;temp6<actnum;temp6++)
{
if(action[temp6].acttype==1)
{
printf("%d:%d ",action[temp6].haptime.tm_hour,action[temp6].haptime.tm_min);
printf("%s到达窗口%d\t",action[temp6].obj,action[temp6].num);
printf("此时节点个数为%d\n",action[temp6].nodeno);
}
else
if(action[temp6].acttype==2)
{
printf("%d:%d ",action[temp6].haptime.tm_hour,action[temp6].haptime.tm_min);
printf("%s在窗口%d完成\t",action[temp6].obj,action[temp6].num);
printf("此时节点个数为%d\n",action[temp6].nodeno);
printf("等待时间为%d:%d\n",action[temp6].waitime.tm_hour,action[temp6].waitime.tm_min);
}
else
printf("unknown transaction!\n");
}
getch();
break;
case 4:
actnum=1;
printf("请输入您要查询的时刻:\n");
printf("时:");
T.tm_hour=gethour();
printf("分");
T.tm_min=getmin();
printf("\n");
head=headpoint->next;
while(!cmptime(head->arrtime,T)&&head->next!=NULL)
{
temp=selectqueue(array,i);
strcpy(temp_node.SNO,head->SNO);
temp_node.arrtime.tm_hour=head->arrtime.tm_hour;
temp_node.arrtime.tm_min=head->arrtime.tm_min;
flag_en=enqueue(array,temp,i,temp_node);
if(flag_en==1)
printf("enqueue succeeded!\n");
else printf("enqueue failed!\n");
head=head->next;
}
dequeueall(array,T,1,i);
registed=1;
system("cls");
swap();
for(temp6=1;temp6<actnum;temp6++)
{
if(action[temp6].acttype==1)
{
printf("%d:%d ",action[temp6].haptime.tm_hour,action[temp6].haptime.tm_min);
printf("%s到达窗口%d\t",action[temp6].obj,action[temp6].num);
printf("此时该队学生个数为%d\n",action[temp6].nodeno);
}
else
if(action[temp6].acttype==2)
{
printf("%d:%d ",action[temp6].haptime.tm_hour,action[temp6].haptime.tm_min);
printf("%s在窗口%d完成\t",action[temp6].obj,action[temp6].num);
printf("此时该队学生个数为%d\n",action[temp6].nodeno);
}
else
printf("unknown transaction!\n");
}
getch();
break;
case 5:
actnum=1;
registed=0;
printf("完成初始化!\n");
getch();
break;
case 6:
head=headpoint->next;
while(head->next!=NULL)
{
printf("%d:",head->arrtime.tm_hour);
printf("%d\n",head->arrtime.tm_min);
head=head->next;
}
getch();
case 0:
printf("\n离开新生报名系统!\n");
return 0;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -