魔术师发牌问题
来源:互联网 发布:拉夏贝尔淘宝旗舰店 编辑:程序博客网 时间:2024/04/26 21:18
#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);
}
0 0
- 魔术师发牌问题
- 魔术师发牌问题
- 魔术师发牌问题
- 魔术师发牌问题(数据结构)
- 魔术师发牌问题
- 魔术师发牌问题
- 魔术师发牌问题
- 魔术师发牌问题
- 魔术师发牌问题2
- 魔术师发牌问题
- 魔术师发牌问题
- 魔术师发牌问题
- 魔术师发牌问题
- 魔术师发牌问题
- 魔术师发牌问题
- 魔术师发牌问题
- 魔术师发牌问题
- 魔术师发牌问题
- 双向循环链表之实践
- 面试:C++中结构体的用法(转)
- java线程面试题
- the xml response contains invalid xml
- Error:No service of type Factory<LoggingManagerInternal> available in ProjectScopeServices.
- 魔术师发牌问题
- hidraw设备自定义设备节点
- 数据库表结构设计方法
- 98. Spring Boot启动流程分析第二篇
- 构建Springboot 1.5.1 Maven工程
- Thumbnailator使用介绍
- java基础面试题
- Debain/Ubuntu的时间设置
- 你需要的基本技术