Data Structure --- c language for bank simulation (discretization), data structure --- c

Source: Internet
Author: User

Data Structure --- c language for bank simulation (discretization), data structure --- c

#include <stdio.h>#include <stdlib.h>#include <windows.h>#define MAX_WIN 20#define MAX_STAY 100typedef 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];}elsewin[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)--;elseleave(i);}}int main(){srand(time(NULL));for(morning; ;later()){come(rand()%MAX_WIN, rand()%MAX_STAY+1);}return 0;}



Because the random number is generated here, the program will remain changing. Press ctrl + c to terminate the program




Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.