最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
C语言数据结构实现银行模拟的教程
时间:2022-06-25 04:35:14 编辑:袖梨 来源:一聚教程网
实现代码:
#include#include #include #define MAX_WIN 20 #define MAX_STAY 100 typedefstructcustomer *link; structcustomer { intstay; link next; }; link GUY(intstay, link next) { link c =malloc(sizeof*c); c->stay = stay; c->next = next; returnc; } link win[MAX_WIN]; voidmorning() { inti; for(i = 0; i < MAX_WIN; i++) { win[i] = NULL; } } voidcome(intw,intstay) { 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); } voidleave(intw) { 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); } } voidguys() { inti; 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); } voidlater() { inti; 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); } } intmain() { srand(time(NULL)); for(morning; ;later()) { come(rand()%MAX_WIN,rand()%MAX_STAY+1); } return0; }
由于这里是生成的随机数,所以程序会一直在变化。按住ctrl +c 终止程序
相关文章
- anthropic claude是什么 入门指南 + 应用场景 05-18
- pixiv官网登录入口直连-pixiv官网快捷登录通道 05-18
- 绝地求生41.1版本更新内容有哪些 05-18
- gemini3.0:完整指南 05-18
- 一耽漫画下载安卓最新版本-一耽漫画app官网入口免费安装 05-18
- openai api 价格 怎么收费?详解 05-18

