一、编程题目
(1)输入某班级学生的姓名、分数,并对分数进行降幂排列并输出;
#include <iostream>
using namespace std;
struct Node
{
char name[100];
int score;
Node *next;
};
void show(Node *head)
{
while(head)
{
cout<<head->name<<" "<<head->score<<endl;
head = head->next;
}
}
int linkLen(Node *head)
{
int len = 0;
while(head)
{
len++;
head = head->next;
}
return len;
}
void sort(Node *head)
{
int len = linkLen(head);
for(int j=len-1; j>0; j--)
{
Node *tempHead = head;
for(int i=0; i<j; i++)
{
if(tempHead->score> tempHead->next->score)
{
char tempName[100];
int tempScore;
strcpy(tempName,tempHead->next->name);
strcpy(tempHead->next->name, tempHead->name);
strcpy(tempHead->name, tempName);
tempScore = tempHead->next->score;
tempHead->next->score = tempHead->score;
tempHead->score = tempScore;
}
}
}
}
int main()
{
char name[100];
int score;
Node *head = NULL;
Node *tail = NULL;
scanf("%s %d", name, &score);
while(score != -1)
{
Node *temp = new Node;
strcpy(temp->name, name);
temp->score = score;
temp->next = NULL;