欢迎来到天天文库
浏览记录
ID:55688207
大小:335.50 KB
页数:15页
时间:2020-05-24
《利用单向链表,实现学生管理系统java练习.doc》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、Java作业:4-13.参照例4-23,利用单向链表,实现学生管理系统。解:运行图:A.主菜单B.增加学生并且打印学生信息C.删除学生信息A.修改学生信息B.查找学生信息代码实现:(1).单向链结点LinkListElement类publicclassLinkListElement{protectedObjectdata;protectedLinkListElementnextElement;publicLinkListElement(Objectv,LinkListElementnext){data=v;nextElement=next;}publicLinkListElement(
2、Objectv){data=v;nextElement=null;}publicLinkListElementnext(){returnnextElement;}publicvoidsetNext(LinkListElementnext){nextElement=next;}publicObjectvalue(){returndata;}publicvoidsetValue(Objectvalue){data=value;}}(2).单向链表LinkList类描述publicclassLinkList{protectedintcount;protectedLinkListElement
3、head;publicLinkList(){head=null;count=0;}publicbooleanisEmpty(){returncount==0;}publicvoidaddToTail(Objectvalue){LinkListElementtemp=newLinkListElement(value,null);if(head!=null){LinkListElementfinger=head;while(finger.next()!=null){finger=finger.next();}finger.setNext(temp);}elsehead=temp;count
4、++;}publicObjectremove(Objectvalue){LinkListElementfinger=head;LinkListElementprevious=null;while(finger!=null&&!finger.value().equals(value)){previous=finger;finger=finger.next();}if(finger!=null){if(previous==null){head=finger.next();}else{previous.setNext(finger.next());}count--;returnfinger.
5、value();}returnnull;}}(3).封装好的学生类importjava.io.*;publicclassStudent{publicStringid;publicStringname;publicStringgrade;publicStringsclass;publicStringqq;publicstaticInputStreamReaderisr=newInputStreamReader(System.in);publicstaticBufferedReaderbr=newBufferedReader(isr);publicStringgetId(){returni
6、d;}publicvoidsetId(Stringid){this.id=id;}publicStringgetName(){returnname;}publicvoidsetName(Stringname){this.name=name;}publicStringgetGrade(){returngrade;}publicvoidsetGrade(Stringgrade){this.grade=grade;}publicStringgetSclass(){returnsclass;}publicvoidsetSclass(Stringsclass){this.sclass=sclas
7、s;}publicStringgetQq(){returnqq;}publicvoidsetQq(Stringqq){this.qq=qq;}publicStudent(Stringid,Stringname,Stringgrade,Stringsclass,Stringqq){this.id=id;this.name=name;this.grade=grade;this.sclass=sclass;this.qq=qq;}publicStud
此文档下载收益归作者所有