資源簡介
火車票訂票系統代碼
代碼片段和文件信息
#include“common.h“
PCbuy?createOneCbuy(PNCustomer?pc?PBticket?pt)
{
PCbuy?pb?=?(PCbuy)malloc(sizeof(NCbuy));
strcpy(pb->b_cname?pc->c_name);
strcpy(pb->b_sstation?pt->b_sstation);
strcpy(pb->b_tstation?pt->b_tstation);
pb->b_trainnu?=?pt->b_trainnu;
pb->b_time?=?pt->b_time;
pb->b_isbuy?=(pt->isBuy);
pb->next?=?NULL;
}
PCbuy?createBuylink(PCbuy?phead)
{
return?phead;
}
PCbuy?searchCbuyByName(PNCustomer?pnc?PCbuy?phead)
{
PCbuy?ptemp?=?phead;
while?(ptemp?!=?NULL)
{
if?(0?==?strcmp(ptemp->b_cname?pnc->c_name))
{
return?ptemp;
}
ptemp?=?ptemp->next;
}
return?ptemp;
}
PCbuy?delOneCbuy(PCbuy?phead?PCbuy?pdel)
{
PCbuy?pri?=?phead;
if?(phead?==?pdel)
{
phead?=?pdel->next;
free(phead);
}
else
{
while?(pri?!=?NULL?&&?pri->next?!=?pdel)
{
pri?=?pri->next;
}
pri->next?=?pdel->next;
free(pdel);
}
return?phead;
}
PCbuy?insertBuylink(PCbuy?phead?PCbuy?pnew)
{
PCbuy?ptemp?=?NULL;
PCbuy?ptail?=?NULL;
//?鏈表中沒有數據,第一次創建鏈表
//?鏈表中只有一條數據
if?(phead->next?==?NULL)
{
phead->next?=?pnew;
return?phead;
}
else
{
while(ptemp->next?!=?NULL)
{
ptemp?=?ptemp->next;
}
ptemp->next?=?pnew;
return?phead;
}
}
void?traverseBuylink(PCbuy?phead)
{
PCbuy?ptemp?=?phead;
int?i?=?0;?
while?(ptemp?!=?NULL)
{
printf(“用戶名=%s?“?ptemp->b_cname);
printf(“起始站=%s?“?ptemp->b_sstation);
printf(“終點站=%s?“?ptemp->b_tstation);
printf(“車次=%d?“?ptemp->b_trainnu);
printf(“達到時間=%d“?ptemp->b_time);
printf(“\n“);
ptemp?=?ptemp->next;?
}
}
void?printOneCbuy(PCbuy?ptemp)
{
printf(“用戶名=%s?“?ptemp->b_cname);
??????? printf(“起始站=%s?“?ptemp->b_sstation);
????????printf(“終點站=%s?“?ptemp->b_tstation);
????????printf(“車次=%d?“?ptemp->b_trainnu);
??????? printf(“達到時間=%d“?ptemp->b_time);
????????printf(“\n“);
}
int?judgeHadBuy(PCbuy?phead?PNCustomer?pc)
{
PCbuy?ptemp?=?phead;
while?(ptemp?!=?NULL)
{
if?(0?==?strcmp(ptemp->b_cname?pc->c_name))
{
return?FAILURE;
}
ptemp?=?ptemp->next;
}
return?SUCCESS;
}
PCbuy??readAllPCbuy()
{
PCbuy?phead?=?NULL;
PCbuy?ptemp?=?NULL;
PCbuy?ptail?=?NULL;
FILE?*f?=?NULL;
f?=?fopen(CBUY_DB?“r+“);
phead?=?(PCbuy)malloc(sizeof(NCbuy));
ptail?=?phead;
?
int?size?=?fread(phead?sizeof(NCbuy)?1?f);
while?(size)
{
ptemp?=?(PCbuy)malloc(sizeof(NCbuy));
size?=?fread(ptemp?sizeof(NCbuy)?1?f);
if?(size?!=?1)
{
free(ptemp);
break;
}
ptail->next?=?ptemp;
ptail?=?ptemp;
}
fclose(f);
return?phead;
}
void?writeAllPCbuy(PCbuy?phead)
{
PCbuy?ptemp?=?phead;
FILE?*f?=?NULL;
f?=?fopen(CBUY_DB?“w+“);?
while?(ptemp?!=?NULL)
{
fwrite(ptemp?sizeof(NCbuy)?1?f);
ptemp?=?ptemp->next;
}
fclose(f);
}
PQueue?createQueue(PCbuy?pcb?int?num)
{
PQueue?phead?=?(PQueue)malloc(sizeof(NQueue));
phead->number?=??num;
phead->isUbook?=?0;
phead->pfront?=?pcb;
return?phead;
}
PQueue?isQueueExist(PQueue*?p?int?num?int?arr_size?int?*pos)
{
int?i?=?0;
for?(i?=?0;?i? {
if?(p[i
- 上一篇:敏感詞過濾+最新敏感詞庫
- 下一篇:計算機專業英語口語學習資料
評論
共有 條評論