20165301第十周课下补做
生活随笔
收集整理的這篇文章主要介紹了
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第十周课下补做的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 打造机器学习工具箱
- 下一篇: 求《冰与火之歌》英文原著1-5mobi格