最新下载
热门教程
- 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 终止程序
相关文章
- 光遇12.26免费魔法有什么 12-26
- 江南百景图碎金泉怎么样 12-26
- 江南百景图游宴廊怎么样 江南百景图游宴廊建筑介绍 12-26
- 江南百景图碎金泉怎么样 江南百景图碎金泉建筑介绍 12-26
- 炉石传说兑换码大全 12-26
- 重返未来1999趋光性研究夜幕之外怎么玩 趋光性夜幕之外活动介绍 12-26