import java.util.*;
public class student
{
class Node
{
public String name ;
public String ID;
public int java ;
public int os;
public int PE;
public int total;
}
public Node data;
public student next;
public student creat()
{
student head,p,r,s1;
int x1,x2,x3,x4;
String n,i;
head=r=null;
System.out.print("请输入学生的姓名 学号 java成绩 os成绩 Internet 成绩");
System.out.print("请输入一个x整形数据以0结束:");
Scanner c= new Scanner(System.in);
n=c.nextLine();
Scanner c0= new Scanner(System.in);
i=c0.nextLine();
Scanner c1= new Scanner(System.in);
x1=c1.nextInt();
Scanner c2= new Scanner(System.in);
x2=c2.nextInt();
Scanner c3= new Scanner(System.in);
x3=c3.nextInt();
while (x1!=0)
{
student s11=new student();
s11.data.name=n;
s11.data.ID=i;
s11.data.java=x1;
s11.data.os=x2;
s11.data.PE=x3;
s11.data.total=s11.data.java+s11.data.os+s11.data.PE;
if(head==null)
head=s11;
else
r.next=s11;
r=s11;
Scanner b= new Scanner(System.in);
n=b.nextLine();
Scanner b0= new Scanner(System.in);
i=b0.nextLine();
Scanner b1= new Scanner(System.in);
x1=b1.nextInt();
Scanner b2= new Scanner(System.in);
x2=b2.nextInt();
Scanner b3= new Scanner(System.in);
x3=b3.nextInt();
}
if(r!=null)
r.next=null;
return head;
}
public void out(student head)
{
student p;
p=head;
System.out.print("List is:");
while(p!=null)
{
System.out.println("\t"+p.data.name+"\t"+p.data.ID+"\t"+p.data.java+"\t"+p.data.os+"\t"+p.data.PE+"\t"+p.data.total);
p=p.next;
}
}
public student sortup(student head)
{
student p=head,pre=null,s=null,q=null;
head.next=null;
while(p!=null)
{
s=p;
p=p.next;
pre=head;
q=head.next;
while(q!=null && q.data.total<s.data.total)
{
pre=q;
q=q.next;
}
s.next=q;
pre.next=s;
}
return head;
}
public student sortdown(student head)
{
student p=head,pre=null,s=null,q=null;
head.next=null;
while(p!=null)
{
s=p;
p=p.next;
pre=head;
q=head.next;
while(q!=null && q.data.total<s.data.total)
{
pre=q;
q=q.next;
}
s.next=q;
pre.next=s;
}
return head;
}
public static void main(String[] args) {
student x,y;
student a=new student();
x=a.creat();
a.out(x);
a.sortdown(x);
a.out(x);
a.sortup(x);
a.out(x);
}
}