代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
Java
】
节点的简单操作
作者:
若夕
/ 发布于
2013/5/28
/
515
public class Demo03{ class People{ private String name; private int age; private People nextpeople; public void setNextPeople(People nextpeople){ this.nextpeople=nextpeople; } public People getNextPeople(){ return nextpeople; } public People(String name,int age){ this.name=name; this.age=age; } public void setName(String name){ this.name=name; } public String getName(){ return name; } public void setAge(int age){ this.age=age; } public int getAge(){ return age; } //判断当前节点是否与指定节点是同一节点 public boolean Equals(People people){ String name=this.getName(); String name1=people.getName(); int age=this.getAge(); int age1=people.getAge(); if(name.equals(name1)&&age==age1){ return true; }else{ return false; } } //通过Name找到节点 public People getPeopleByName(String name){ People people=this,peo=null; do{ String name1=people.getName(); if(name.equals(name1)){ peo=people; break; }else{ people=people.nextpeople; } }while(people!=null); return peo; } public void println(){ System.out.println("Name:"+name+",Age:"+age); } } private People rootpeople,currentpeople,people; //设置节点 public void setPeople(String name,int age){ currentpeople=new People(name,age); if(rootpeople==null){ rootpeople=currentpeople; people=rootpeople; }else{ if(people.nextpeople==null){ people.nextpeople=currentpeople; } people=people.nextpeople; } } //显示节点 public void showList(){ rootpeople.println(); people=rootpeople; if(people.nextpeople!=null){ rootpeople=people.nextpeople; showList(); } } //显示节点 public void show(){ people=rootpeople; do{ people.println(); people=people.nextpeople; }while(people!=null); } //删除节点 public void deletePeople(String name,int age){ People people=new People(name,age); if(rootpeople.Equals(people)){ System.out.println("该节点已删除,Name:"+rootpeople.getName()+",Age:"+rootpeople.getAge()); rootpeople=rootpeople.nextpeople; }else{ currentpeople=rootpeople.nextpeople; if(currentpeople.Equals(people)){ System.out.println("该节点已删除,Name:"+currentpeople.getName()+",Age:"+currentpeople.getAge()); rootpeople.nextpeople=currentpeople.nextpeople; }else{ rootpeople=currentpeople; deletePeople(name,age); } } } //增加节点 public void addPeople(String name,int age){ People people=new People(name,age); currentpeople=rootpeople; do{ if(currentpeople.nextpeople!=null){ currentpeople=currentpeople.nextpeople; }else{ currentpeople.nextpeople=people; break; } }while(currentpeople!=null); } //在指定位置添加节点 public void addNextPeopleByName(String oldname,String name,int age){ People peo=rootpeople.getPeopleByName(oldname); People people=new People(name,age); people.nextpeople=peo.nextpeople; peo.nextpeople=people; } //修改指定节点的信息 public void updatePeopleByName(String oldname,String newname){ People peo=rootpeople.getPeopleByName(oldname); peo.setName(newname); } public static void main(String[] args){ Demo03 d1=new Demo03(); d1.setPeople("aaa",20); d1.setPeople("bbb",21); d1.setPeople("ccc",22); d1.setPeople("ddd",23); d1.setPeople("eee",24); d1.setPeople("fff",25); d1.setPeople("ggg",26); d1.show(); d1.deletePeople("aaa",20); d1.show(); d1.deletePeople("ccc",22); d1.show(); System.out.println(); d1.addPeople("hhh",27); d1.show(); System.out.println(); d1.addNextPeopleByName("eee","iii",28); d1.show(); System.out.println(); d1.updatePeopleByName("fff","qqq"); d1.show(); } }
试试其它关键字
节点操作
同语言下
.
List 切割成几份 工具类
.
一行一行读取txt的内容
.
Java PDF转换成图片并输出给前台展示
.
java 多线程框架
.
double类型如果小数点后为零则显示整数否则保留两位小
.
将图片转换为Base64字符串公共类抽取
.
sqlParser 处理SQL(增删改查) 替换schema 用于多租户
.
JAVA 月份中的第几周处理 1-7属于第一周 依次类推 29-
.
java计算两个经纬度之间的距离
.
输入时间参数计算年龄
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
若夕
贡献的其它代码
(
2
)
.
session 购物车类
.
节点的简单操作
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3