C 언어 데이터 구 조 는 은행 시 뮬 레이 션 을 실현 한다.
2646 단어 C 언어데이터 구조은행 시 뮬 레이 션
구현 코드:
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#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 종료 프로그램 누 르 기이상 은 C 언어 데이터 구조 가 은행 시 뮬 레이 션 을 실현 하 는 사례 에 대한 상세 한 설명 입 니 다.궁금 한 점 이 있 으 면 메 시 지 를 남기 거나 본 사이트 지역사회 에 가서 토론 을 하 십시오.읽 어 주 셔 서 감사합니다. 여러분 께 도움 이 되 기 를 바 랍 니 다.본 사이트 에 대한 지지 에 감 사 드 립 니 다!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
C 언어 구현 천둥 제거 게임 상세 정보먼저 작은 메뉴를 표시하고 게임을 할지 여부를 선택하십시오.사용자가 종료를 선택하면 프로그램 실행이 끝나고, 사용자가 게임을 선택하면 지뢰 제거 위치 좌표를 입력하라는 메시지가 표시됩니다.사용자가 입력한 좌표가 바둑...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.