C语言24点游戏链表报告,C++新人一枚,24点链表,都快做哭了。。。。。。。。。...

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

题目要求:24点游戏,并且用链表保存每次游戏的数字。。。。。。

LZ表示一个24点就够烦人的了,还要用链表,一点都不会呀,几天百度下来就搞了个这样。。。。。24点没问题了,只贴上链表和主函数代码

—————————————————————————————————————————

struct node{

int info;

node *link;

struct node *next;

};

struct node *create(int *numnode){

int p[4];

int i;

struct node *head,*tail,*cnew;

head=NULL;

p[0]=M.A;

p[1]=M.B;

p[2]=M.C;

p[3]=M.D;

for(i=0;i<4;i++)

{

cnew=(struct node*)malloc(sizeof(struct node));

cnew->info=p[i];

cnew->next=NULL;

if(head==NULL)

head=cnew;

else

tail->next=cnew;

tail=cnew;

(*numnode)++;

}

return head;

}

void show(struct node *head){

struct node *p;

if(head==NULL)

{

printf("链表为空,没有数据\n");

}

printf("\n");

for(p=head;p!=NULL;p=p->next)

printf("%d ",p->info);

printf("\n");

}

int main()

{

struct node *head;

head=NULL;

double num[4];

string str[4];

for(;;){

int numnode;

numnode=0;

int i;

int B;

int Q;

int temp;

char tempstr[4] = {0};

srand(time(NULL));

for (i=0;i<4;i++)

{

temp=rand()%13+1;

itoa(temp,tempstr,10);

num[i]=temp;

str[i]=tempstr;

}

cout<

for (i=0;i<4;i++)

{

cout<

}

M.A=num[0];

M.B=num[1];

M.C=num[2];

M.D=num[3];

cout<

cout<

cin>>B;

switch(B){

case 1:{

cout<

if(!CAL(4,num,str))

cout<

break;

case 2:{

head=create(&numnode);

show(head);}

break;}

cout<

cin>>Q;

switch(Q){

case 1:break;

case 2:exit(0);}

}

}

结果链表只保存最后一次数据。。。。。。。怎么破

df0d8fa310c63b760fd0a3795e0810ae.gifLZ快疯掉了,求教呀。。。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值