请帮忙,只是冒泡法排序而已.急!!!(100分)

  • 主题发起人 主题发起人 magic6326
  • 开始时间 开始时间
M

magic6326

Unregistered / Unconfirmed
GUEST, unregistred user!
#include "stdafx.h"
#include "iostream.h"
#define SIZE 10
struct Player_type
{
char name[20];
int Guesses;
}player[SIZE];
int _tmain(int argc, _TCHAR* argv[])
{
int i,j,l;
Player_type trname;
for (j=0;j<SIZE;j++)player[j].Guesses=j+10;
cout<<"Please enter your name ->";
cin>>player[SIZE].name;
cout<<"Please enter your No ->";
cin>>player[SIZE].Guesses;
for (j=0;j<=SIZE-1;j++)
for(i=0;i<SIZE-j;i++)
{ if(player.Guesses>player[i+1].Guesses)
{
1 for (l=0;l<=20;l++)trname.name[l]=player.name[l];
2 for (l=0;l<=20;l++)player.name[l]=player[i+1].name[l];
3 for (l=0;l<=20;l++)player[i+1].name[l]=trname.name[l];
trname.Guesses=player.Guesses;
player.Guesses=player[i+1].Guesses;
player[i+1].Guesses=trname.Guesses;
};
};
for (j=0;j<=SIZE-1;j++)
cout<<player[j].name<<" "<<player[j].Guesses<<endl;
cin>>l;
return 0;
}
不知怎么,就是player.Guesses排序不成功,注释掉1,2,3句的话就可以.为什么?我希望是两个一起排序啊!
 
#include "stdafx.h"
#include "iostream.h"
#define SIZE 10
struct Player_type
{
char name[20];
int Guesses;
}player[SIZE];
int _tmain(int argc, _TCHAR* argv[])
{
int i,j,l;
Player_type trname;
for (j=0;j<SIZE;j++)player[j].Guesses=j+10;
cout<<"Please enter your name ->";
cin>>player[SIZE].name;
cout<<"Please enter your No ->";
cin>>player[SIZE].Guesses;
for (j=0;j<=SIZE-1;j++)
for(i=0;i<SIZE-j;i++)
{ if(player.Guesses>player[i+1].Guesses)
{
for (l=0;l<20;l++)trname.name[l]=player.name[l];
for (l=0;l<20;l++)player.name[l]=player[i+1].name[l];
for (l=0;l<20;l++)player[i+1].name[l]=trname.name[l];
trname.Guesses=player.Guesses;
player.Guesses=player[i+1].Guesses;
player[i+1].Guesses=trname.Guesses;
};
};
for (j=0;j<=SIZE-1;j++)
cout<<player[j].name<<" "<<player[j].Guesses<<endl;
cin>>l;
return 0;
}
 
接受答案了.
 
后退
顶部