模拟银行客户逗留平均时间
数据结构(C语言版)中栈的习题
#include<stdlib.h>
#include<stdio.h>
#include<malloc.h>
#include<conio.h>
#define ERROR 0
#define OK 1
typedef struct{
int OccurTime;
int NType;
}Event;
typedef struct{
int ArrivalTime;
int Duration;
}QElemType;
struct LNODE
{
Event data;
struct LNODE *next;
};
typedef struct LNODE LNode;
typedef struct LNODE *LinkList;
typedef struct LNODE *EvenList;
typedef struct QNode{
QElemType elem;
struct QNode *next;
}QNode,*QueuePtr;
typedef struct
{ QueuePtr front;
QueuePtr rear;
}LinkQueue;
EvenList ev;
Event en;
LinkQueue q[5];
QElemType customer;
int TotalTime,CustomerNum,CloseTime;
int InitList(EvenList *L)
{
*L=(LNode *)malloc(sizeof(LNode));
if(!(*L)) exit(ERROR);
(*L)->next=NULL;
return OK;
}
int DelFirst(EvenList *L,Event *e)
{ LNode *pc,*q;
pc=*L;q=pc->next;
pc->next=q->next;*e=q->data;return OK;}
int ListEmpty(LNode L)
{LNode *p;
int j=0;
p=L.next;
while(p)
{j++;break;}
if(j==0) return 1;
else return 0;
}
int compare(Event a,Event b)
{ if(a.OccurTime>b.OccurTime) return 1;
else if(a.OccurTime==b.OccurTime) return 0;
else return -1;
}
int OrderInsert(EvenList *L,Event e,int (* cmp)(Event ,Event ))
{ LNode *p,*pc;/*把事件插入链表*/
p=(LNode *)malloc(sizeof(LNode));/*分配空间*/
if(!p) { printf("not"); return(0);}
if(ListEmpty(**L))
{ p->data=e;p->next=(*L)->next;(*L)->next=p;}
else {
switch(cmp(((*L)->next)->data,e))
{case -1:pc=(*L)->next;
while(pc->next!=NULL)
{
if((pc->next)->data.OccurTime<=e.OccurTime)
pc=pc->next;
else break;
}
p->data=e;p->next=pc->next;/*把它接在比它大的前*/
pc->next=p;break;
&nbs
补充:asp.net教程,C语言
上一个:快速排序&静态链表的插入排序
下一个:查找算法