开发者

I can't figure out why my linked lists don't work

开发者 https://www.devze.com 2023-01-30 00:26 出处:网络
here is what I am trying to do开发者_C百科 to get it back out. linked n = stu; int d = datainput.readInt();

here is what I am trying to do开发者_C百科 to get it back out.

        linked n = stu;

        int d = datainput.readInt();
        for(int x = 0; x < d; x++){
            students student = new students();
            student.setlname(datainput.readUTF());
            student.setfname(datainput.readUTF());
            student.setAge(datainput.readShort());
            student.setSex(datainput.readChar());
            student.setRace(datainput.readChar());

            int coucounter = datainput.readInt();
            linked cou = student.getCou();
            for(int y = 0; y < coucounter; y++){
                System.out.print("WTF");
                courses course = new courses();
                course.setName(datainput.readUTF());
                course.setDept(datainput.readUTF());
                course.setHours(datainput.readShort());
                course.setGrade(datainput.readChar());
                cou.setObject(course);  //Something wrong here
                cou = cou.getNext();

            }
            n.setObject(student);
            n = n.getNext();

        }

EDIT: Here is my linked class

public class linked {
    private Object ob;
    private linked next;

    linked(){
    }

    void setNext(linked l){
        next = l;
    }

    void setObject(Object o){
        ob = o;
    }

    linked getNext(){
        return next;
    }

    Object getObject(){
        return ob;
    }
}


Found it.

                cou.setObject(course);
                cou.setNext(new linked());
                cou = cou.getNext();

and

            n.setObject(student);
            n.setNext(new linked());
            n = n.getNext();

odd since when I used my linked lists before I didn't need to do this and the class is exactly the same. Oh well! Works now! WOOT

0

精彩评论

暂无评论...
验证码 换一张
取 消