zoukankan      html  css  js  c++  java
  • 数据结构-单链表与排序(选做)

    任务要求

    • 补充MyList.java的内容,提交运行结果截图(全屏),课下推送代码到码云
    public class MyList {
    	public static void main(String [] args) {
    		//选用合适的构造方法,用你学号前后各两名同学的学号创建四个结点
    		
    		
    		//把上面四个节点连成一个没有头结点的单链表
    		
    		//遍历单链表,打印每个结点的
    
    		//把你自己插入到合适的位置(学号升序)
    
    		//遍历单链表,打印每个结点的
    
    		//从链表中删除自己
    
    		//遍历单链表,打印每个结点的
    	}
    }
    
    public class Node<T>                             //单链表结点类,T指定结点的元素类型
    {
        public T data;                               //数据域,存储数据元素
        public Node<T> next;                         //地址域,引用后继结点
    
        public Node(T data, Node<T> next)            //构造结点,data指定数据元素,next指定后继结点
        {
            this.data = data;                        //T对象引用赋值
            this.next = next;                        //Node<T>对象引用赋值
        }
        public Node()
        {
            this(null, null);
        }
        public String toString()                     //返回结点数据域的描述字符串
        {
            return this.data.toString();
        }
    }
    
    • 在数据结构和算法中,排序是很重要的操作,要让一个类可以进行排序,有两种方法:
      • 有类的源代码,针对某一成员变量排序,让类实现Comparable接口,调用Collection.sort(List)
      • 没有类的源代码,或者多种排序,新建一个类,实现Comparator接口 调用Collection.sort(List, Compatator)
        针对下面的Student类,使用Comparator编程完成以下功能:
    1. 在测试类StudentTest中新建学生列表,包括自己和学号前后各两名学生,共5名学生,给出运行结果(排序前,排序后)
    2. 对这5名同学分别用学号和总成绩进行增序排序,提交两个Comparator的代码
    3. 课下提交代码到码云
    class Student {
        private String id;//表示学号
        private String name;//表示姓名
        private int age;//表示年龄
        private double computer_score;//表示计算机课程的成绩
        private double english_score;//表示英语课的成绩
        private double maths_score;//表示数学课的成绩
        private double total_score;// 表示总成绩
        private double ave_score; //表示平均成绩
    
        public Student(String id, String name){
            this.id = id;
            this.name = name;
    }
        public Student(String id, String name, char sex, int age){
            this(id, name);
            this.sex = sex;
            this.age = age;
    }
        public String getId(){
            return id;
    }//获得当前对象的学号,
        public double getComputer_score(){
            return computer_score;
    }//获得当前对象的计算机课程成绩,
        public double getMaths_score(){
            return maths_score;
    }//获得当前对象的数学课程成绩,
        public double getEnglish_score(){
            return english_score;
    }//获得当前对象的英语课程成绩,
    
        public void setId(String id){
            this.id=id;
    }// 设置当前对象的id值,
        public void setComputer_score(double computer_score){
            this.computer_score=computer_score;
    }//设置当前对象的Computer_score值,
        public void setEnglish_score(double english_score){
            this.english_score=english_score;
    }//设置当前对象的English_score值,
        public void setMaths_score(double maths_score){
            this.maths_score=maths_score;
    }//设置当前对象的Maths_score值,
    
        public double getTotalScore(){
            return computer_score+maths_score+english_score;
    }// 计算Computer_score, Maths_score 和English_score 三门课的总成绩。
        public double getAveScore(){
            return getTotalScore()/3;
    }// 计算Computer_score, Maths_score 和English_score 三门课的平均成绩。
    
    }
    
    class Undergraduate extends Student{
        private String classID;
    
        public Undergraduate(String id, String name, char sex, int age,String classID){
            super(id,name,sex,age);
            this.classID=classID;
        }
        public String getClassID(){
            return classID;
        }
        public void setClassID(String classID){
            this.classID=classID;
        }
    }
    

    实验结果


    码云链接

    https://gitee.com/J20175319/java20175319_jiangye/tree/master/week10/数据结构选做/src

  • 相关阅读:
    sizeof注意
    如何获取存储过程的返回值和输出值
    OA、ERP、SRM、PLM、CAPP、MES、LIMS、CRM
    js1号脚本
    Python各类常用库整理
    Html设计器
    python从入门到放弃之图像处理
    C# Web API操作Sqlite数据库
    C# Naudio 从麦克风输入到声卡输出 录音 放音功能
    WPF/MVVM模式入门教程(二):实现INotifyPropertyChanged接口
  • 原文地址:https://www.cnblogs.com/killer-queen/p/10816907.html
Copyright © 2011-2022 走看看