日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

20165301第十周课下补做

發布時間:2025/5/22 编程问答 15 豆豆
生活随笔 收集整理的這篇文章主要介紹了 20165301第十周课下补做 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

第十周課下補做

知識點總結

  • 創建一個空的鏈表
    List<Student> list = new LinkedList<Student>();

  • 向鏈表中添加新的結點
    list.add(new Student(XXXXXXXXXXXXXXX));

  • 刪除結點
    list.remove("xxxxxxx");

  • 鏈表中數據的插入
    list.add("**");

  • 鏈表中數據的排序
    Collections.sort();

  • 將list中的元素按升序排序
    public static sort(List<E>list)

習題2

代碼
import java.util.*; class StudentSort implements Comparable {double d=0;String s="";StudentSort (double d) {this.d=d;}StudentSort (String s) {this.s=s;}public int compareTo(Object b) {StudentSort st=(StudentSort)b;if((this.d-st.d)==0)return -1;elsereturn (int)((this.d-st.d)*1000);} } class Student {String name=null;double math,english,computer,total,aver;Student(String s, double m, double e, double f, double a,double b) {name=s;math=m;english=e;computer=f;total=a;aver=b;} } public class paixu {public static void main(String args[]) {TreeMap<StudentSort, Student> treemap = new TreeMap<StudentSort, Student>();String str[] = {"20165301陳潭飛", "20165302程上杰", "20165338胡麟", "20165303魏煜", "20165339唐羽童"};double math[] = {89, 48, 74, 76, 70};double english[] = {62, 69, 69, 70, 71};double computer[] = {99, 66, 54, 75, 80};double total[] = new double[5];double aver[] = new double[5];Student student[] = new Student[5];for (int k = 0; k < student.length; k++) {total[k] = math[k] + english[k] + computer[k];aver[k] = total[k] / 3;}for (int k = 0; k < student.length; k++) {student[k] = new Student(str[k], math[k], english[k], computer[k], total[k], aver[k]);}StudentSort key[] = new StudentSort[5];for (int k = 0; k < key.length; k++) {key[k] = new StudentSort(student[k].total);}for (int k = 0; k < student.length; k++) {treemap.put(key[k], student[k]);}int number = treemap.size();System.out.println("有" + number + "個對象,按總成績排序:");Collection<Student> collection = treemap.values();Iterator<Student> iter = collection.iterator();while (iter.hasNext()) {Student stu = iter.next();System.out.println("姓名 " + stu.name + " 總成績 " + stu.total);}} }
實驗截圖

習題三

代碼
import java.util.*; public class MyList {public static void main(String [] args) {List<String> list=new LinkedList<String>();list.add("20165305");list.add("20165302");list.add("20165303");list.add("20165304");System.out.println("打印初始鏈表");//把上面四個節點連成一個沒有頭結點的單鏈表Iterator<String> iter=list.iterator();while(iter.hasNext()){String te=iter.next();System.out.println(te);}//遍歷單鏈表,打印每個結點的list.add("20165301");//把你自己插入到合適的位置(學號升序)System.out.println("插入我的學號后排序,打印鏈表");Collections.sort(list);iter=list.iterator();while(iter.hasNext()){String te=iter.next();System.out.println(te);}//遍歷單鏈表,打印每個結點的list.remove("20165301");//從鏈表中刪除自己System.out.println("刪除我的學號后打印鏈表");iter=list.iterator();while(iter.hasNext()){String te=iter.next();System.out.println(te);}//遍歷單鏈表,打印每個結點的} }
實驗截圖

教材課后作業

  • 使用堆棧結構輸出an的若干項,其中an=2an-1+2an-2,a1=3,a2=8.

  • 將鏈表中的學生英語成績單存放到一個樹集中,使得按成績自動排序,并輸出排序結果

  • 有10個U盤,有兩個重要的屬性:價格和容量,編寫一個應用程序,使用TreeMap

轉載于:https://www.cnblogs.com/CTF5301/p/8998535.html

總結

以上是生活随笔為你收集整理的20165301第十周课下补做的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。