魔术师发牌问题

C语言链表实现与应用
#include<stdio.h>
#include<malloc.h>
#define Max 13
typedef struct card
{
int n;
struct card *next;
}Card;
//初始化 
void initList(Card **head);
//销毁链表
void destroyList(Card **head); 
//发牌
void startList(Card **head); 
//显示
void showList(Card head); 
void showList(Card head)
{
Card *p=NULL;
int i=0;
int k=0;
p=head.next;
while(k<Max)
{
printf("(第%d张)黑桃%d\n",++i,p->n);
p=p->next;
k++;
}
}
void startList(Card **head)
{
int count=1;
Card *p=NULL,*q=NULL;
int i;
p=(*head);


while(count<=13)
{
for(i=0;i<count;i++)
{
p=p->next;
if((p->n)!=0)
{

   i--;
}

}
p->n=i;
printf("%d",p->n);
count++;
}


void destroyList(Card **head)
{
Card *p=NULL,*q=NULL;
q=(*head)->next;
while(q!=NULL)
{
p=q->next;
free(q);
q=p;
}
free(*head);
}
void initList(Card **head)
{
Card *p=NULL,*q=NULL;
int k=0;
(*head)=(Card *)(malloc(sizeof(Card)));

while(k<Max)
{
q=(Card *)(malloc(sizeof(Card)));
k++;
if(k==1)
{
(*head)->next=q;
}
else   
{
p->next=q;
}
p=q;
p->n=0;
}
p->next=(*head)->next;
}
int main()
{
Card  *head=NULL;
initList(&head);
startList(&head); 
showList(*head);
 










评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值