该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
题目要求: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);}
}
}
结果链表只保存最后一次数据。。。。。。。怎么破
LZ快疯掉了,求教呀。。。