Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 求教一个数据结构--链表
cfcccvc





发贴: 2
积分: 0
于 2005-11-27 22:29 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
各位大虾好,小弟初学java数据结构,编了一个链表的程序,却苦于无法运行,望各位给检查检查,谢谢啦!!

import java.io.*;
import java.applet.Applet;
public class LinkedListApplet extends Applet{
public void init() {
LinkedList=new LinkedList();
L.insertNewLastNode("DUS");
L.insertNewLastNode("ORD");
L.insertNewLastNode("SAN");
L.print();
L.insertNewSecondNode("BRU");
L.print();
L.deleteLastNode();
L.print();
}
}
//ListNode类定义
public class ListNode{
String airport;
ListNode link;
}
//LinkedList类定义
public class LinkedList{
int length;
ListNode firstNode;
public int size(){
return length;
}
insertNewSecondNode(airportCode)
listSearch(airportCode)
deleteLastNode()
insertNewLastNode(airportCode)
print()
}
//插入新的次节点的方法
public void instertNewSecondNode(String airportCode){
if(length==0) return;
ListNode newNode=new ListNode();
newNode.airport=airportCode;
newNode.link=firstNode.link;
firstNode.link=newNode;
return airportCode;
length++;
}
//搜索
public ListNode listSearch(String airportCode){
ListNode N;
N=firstNode;
while(N!=null){
if(airportCode.equals(N.airport){
return N;
}
else {
N=N.link;
}

return N;
}
//删除链表末端节点
public void deleteLastNode(){
ListNode PreviousNode.currentNode;
if(firstNode!=null){
if(firstNode.link++null){
firstNode=null;
length--;
}else{
previousNode=firstNode;
currentNode=firstNode.link;
while(currentNode.link !=null){
previousNode=currentNode;
currentNode=currentNode.link;
}
previousNode.link=null;
length--;;
}
}
}
//插入新的末端节点
public void insertNewLastnode(String airportCode){
ListNode N= new ListNode();
N.airport=airportCode;
N.link=null;
if(firstNode==null){
firstNode=N;
}else{
ListNode P=firstNode;
while(P.link!=null){
P=P.link;
}
P.link=N;
}
length++;
}
//打印链表
public void print(){
ListNode N;
System.out.print("(");
N=firstNode;
while(N!=null){
System.out.print(N.airport);
N=N.link;
if(N!=null){
System.out.print(",");
}
}
System.out.println(")");

新手上路,请多指教!




话题树型展开
人气 标题 作者 字数 发贴时间
4719 求教一个数据结构--链表 cfcccvc 2075 2005-11-27 22:29
3516 Re:求教一个数据结构--链表 ranchgirl 64 2005-11-28 10:39
3543 Re:求教一个数据结构--链表 cfcccvc 472 2005-11-28 12:12
3670 Re:求教一个数据结构--链表 ranchgirl 407 2005-11-28 12:34

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923