c语言中离散化,数据结构之---C语言实现银行模拟(离散化)

数据结构之---C语言实现银行模拟(离散化)

#include #include #include #define MAX_WIN 20

#define MAX_STAY 100

typedef struct customer *link;

struct customer

{

int stay;

link next;

};

link GUY(int stay, link next)

{

link c = malloc(sizeof *c);

c->stay = stay;

c->next = next;

return c;

}

link win[MAX_WIN];

void morning()

{

int i;

for(i = 0; i < MAX_WIN; i++)

{

win[i] = NULL;

}

}

void come(int w, int stay)

{

if(win[w] == NULL)

{

win[w] = GUY(stay, NULL);

win[w]->next = win[w];

}

else

win[w] = win[w]->next = GUY(stay, win[w]->next);

}

void leave(int w)

{

if(win[w]->next == win[w])

{

free(win[w]);

win[w] = NULL;

}

else

{

link t = win[w]->next;

win[w]->next = t->next;

free(t);

}

}

void guys()

{

int i;

link t;

system(clear);

for(i = 0; i < MAX_WIN; i++, puts( ))

{

printf(WIN%3d:_, i);

if((t = win[i]) == NULL)

continue;

for(; t->next != win[i]; t = t->next)

{

printf(%4d, t->next->stay);

}

}

Sleep(1);

}

void later()

{

int i;

for(guys(), i = 0; i < MAX_WIN; i++)

{

if(win[i] == NULL)

continue;

if(win[i]->next->stay > 0)

(win[i]->next->stay)--;

else

leave(i);

}

}

int main()

{

srand(time(NULL));

for(morning; ;later())

{

come(rand()%MAX_WIN, rand()%MAX_STAY+1);

}

return 0;

}

由于这里是生成的随机数,所以程序会一直在变化。按住ctrl +c 终止程序

9d1d208b83564bbb49f8de335870bceb.png

8f04cda4ec190253f5a0c4d1b23e5da0.png

http://www.dengb.com/Cyy/1055438.htmlwww.dengb.comtruehttp://www.dengb.com/Cyy/1055438.htmlTechArticle数据结构之---C语言实现银行模拟(离散化) #include #include #include #define MAX_WIN 20#define MAX_STAY 100typedef struct customer *link;struct customer{int stay;l...

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值