如何编写哈希数据结构?

时间:2019-06-25 00:19:08

标签: c#

因此,我正在尝试使用哈希数据结构开发程序。我必须尝试存储8位数字的学生ID并检索数据。学生数据还包括GPA,专业和电子邮件地址。我在哈希数据结构的麻烦代码。部分原因是我不太了解。我在做什么错了?

 namespace Hashing
 {
class Student
{
    private String name;
    private double GPA;
    private String major;
    private String email;

    public Student()
    {

    }
    public Student(String name, double gPA, String major, String email)
    {
        this.name = name;
        GPA = gPA;
        this.major = major;
        this.email = email;
    }
    public String getName()
    {
        return name;
    }
    public void setName(String name)
    {
        this.name = name;
    }
    public double getGPA
    {
        return GPA;
    }
    public void setGPA(double gPA)
    {
        GPA = gPA;
    }
    public String getMajor()
    {
        return major;
    }
    public void setMajor(String major)
    {
        this.major = major;
    }
    public String getEmail()
    {
        return email;
    }
    public void setEmail(String email)
    {
        this.email = email;
    }

}
public class StudentData
{
    public HashSet<String, Student> studentMap = new HashSet<String, 
Student>();
    public<T>void set(String key, Task value)
    {
        studentMap.put(key, (Student)value);
    }
    public <T> T get(String key)
    {
        return (T)studentMap.get(key);
    }
    public static void main(String[] args)
    {
        StudentData studentData = new StudentData();
        studentData.set("00158268", new Student("John Smith", 4.5, "CS", 
"johnsmith@in.com"));
    }
}
}

0 个答案:

没有答案