Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

d) if (ItempHead) templHead- new node: tempHead- nexts -headsi temp Head-onextT

ID: 3784630 • Letter: D

Question

d) if (ItempHead) templHead- new node: tempHead- nexts -headsi temp Head-onextT headT tempHead- nextW -headw; if (!heads) to add by tine stamo heads new node: heads- linked add (timestamp, temperature, windspeed) heads- nexts NULL else node Current heads: node prev NULL if (!current- linked-checkTime (timestamp)) node temp new node: temp- linked-add (timestamp, temperature, windspeed); tempo- nexts heads: heads tempo; else while (current- nexts && !current- linked. checkTime (timestamp)) prev current current current->nexts; if current->nexts) if (current- linked. checkTime (timestamp) node temp new node temp- linked. add (timestamp, temperature, windsp current->nexts tempi temp->nexts -NULL else node temp new node: temp- linked. add (timestamp, temperature, windspeed) temp->nexts current; prev- nexts tempi

Explanation / Answer


import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;

public class MyLinkedListSort {

    public static void main(String a[]){
         
        LinkedList<Empl> list = new LinkedList<Empl>();
        list.add(new Empl("Ram",3000));
        list.add(new Empl("John",6000));
        list.add(new Empl("Crish",2000));
        list.add(new Empl("Tom",2400));
        Collections.sort(list,new MySalaryComp());
        System.out.println("Sorted list entries: ");
        for(Empl e:list){
            System.out.println(e);
        }
    }
}

class MySalaryComp implements Comparator<Empl>{

    @Override
    public int compare(Empl e1, Empl e2) {
        if(e1.getSalary() < e2.getSalary()){
            return 1;
        } else {
            return -1;
        }
    }
}

class Empl{
     
    private String name;
    private int salary;
     
    public Empl(String n, int s){
        this.name = n;
        this.salary = s;
    }
     
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getSalary() {
        return salary;
    }
    public void setSalary(int salary) {
        this.salary = salary;
    }
    public String toString(){
        return "Name: "+this.name+"-- Salary: "+this.salary;
    }
}