#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);
}
#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);
}