该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

2019-08-25

链表学习续

实现数据内容查询功能

interface ILink{//创建一个接口用于定义方法标准

//定义增加方法

public void add(E e) ;

//定义获取元素个数方法

public int getLength();

//判断是否为空集合

public boolean isEmpty();

//定义返回链表数据方法(返回数据为数组形式,为了通用性类型设置为Object)

public Object [] toArray() ;

//定义根据索引索取数据

public E get(int index) ;

//定义修改数据方法

public void set(int index, E data) ;

//定义数据内容查询功能

public boolean contains(E data) ;

}

class LinkImpl implements ILink{//创建一个子类继承ILink接口

private Node root ;

@Override

public void add(E e){

if(e == null){

return ;

}

Node newNode = new Node(e);

if(this.root == null){

this.root = newNode ;

}else{

this.root.addNode(newNode) ;

}

this.count ++ ;

}

private int count ;

@Override

public int getLength(){

return this.count ;

}

@Override

public boolean isEmpty(){

if (this.count == 0){

return true ;

}else{

return false ;

}

}

private int foot ;

private Object [] returnData ;

@Override

public Object [] toArray(){

if(this.isEmpty()){

throw new NullPointerException("空集合");

}

this.foot = 0 ;

this.returnData = new Object [this.count] ;

this.root.toArrayNode();

return this.returnData ;

}

@Override

public E get(int index){

if(index >= this.count){

throw new ArrayIndexOutOfBoundsException("指定索引不在范围之内");

}else{

this.foot = 0 ;

return this.root.getNode(index) ;

}

}

@Override

public void set(int index, E data){

if(index >= this.count){

throw new ArrayIndexOutOfBoundsException("指定索引不在范围之内");

}else{

this.foot = 0 ;

this.root.setNode(index,data) ;

}

}

@Override

public boolean contains(E data){

if(data == null){

return false ;

}else{

return this.root.containsNode(data) ;

}

}

//-------------------以上为接口子类,以下为内部类---------------------------

private class Node{//创建内部类用于实现引用关系的处理

private E data ;//用于节点保存数据

private Node next ;//用于节点的引用关系

public Node(E data){//创建节点是保存数据

this.data = data ;

}

//保存新的节点数据

public void addNode(Node newNode){

if(this.next == null){

this.next = newNode ;

}else{

this.next.addNode(newNode) ;

}

}

public void toArrayNode(){

LinkImpl.this.returnData[LinkImpl.this.foot ++] = this.data ;

if(this.next != null){

this.next.toArrayNode() ;

}

}

public E getNode(int index){

if(LinkImpl.this.foot ++ == index){

return this.data ;

}else{

return this.next.getNode(index) ;

}

}

public void setNode(int index, E data){

if(LinkImpl.this.foot ++ == index){

this.data = data ;

}else{

this.next.setNode(index,data) ;

}

}

public boolean containsNode(E data){

if(this.data.equals(data)){

return true ;

}else{

if(this.next == null){

return false ;

}else{

return this.next.containsNode(data) ;

}

}

}

}

}

public class LinkDemo{

public static void main(String args[]){

ILink link = new LinkImpl () ;

link.add("Hello");

link.add("World");

link.add("Allan");

link.add("Tom");

System.out.println(link.getLength()) ;

System.out.println(link.isEmpty()) ;

link.set(2,"你好!!!") ;

System.out.println(link.get(2));

System.out.println(link.contains("你好!!!"));

System.out.println(link.contains("2212"));

}

}

实现删除链表数据功能

interface ILink{//创建一个接口用于定义方法标准

//定义增加方法

public void add(E e) ;

//定义获取元素个数方法

public int getLength();

//判断是否为空集合

public boolean isEmpty();

//定义返回链表数据方法(返回数据为数组形式,为了通用性类型设置为Object)

public Object [] toArray() ;

//定义根据索引索取数据

public E get(int index) ;

//定义修改数据方法

public void set(int index, E data) ;

//定义数据内容查询功能

public boolean contains(E data) ;

//定义删除数据功能

public void remove(E e) ;

}

class LinkImpl implements ILink{//创建一个子类继承ILink接口

private Node root ;

@Override

public void add(E e){

if(e == null){

return ;

}

Node newNode = new Node(e);

if(this.root == null){

this.root = newNode ;

}else{

this.root.addNode(newNode) ;

}

this.count ++ ;

}

private int count ;

@Override

public int getLength(){

return this.count ;

}

@Override

public boolean isEmpty(){

if (this.count == 0){

return true ;

}else{

return false ;

}

}

private int foot ;

private Object [] returnData ;

@Override

public Object [] toArray(){

if(this.isEmpty()){

throw new NullPointerException("空集合");

}

this.foot = 0 ;

this.returnData = new Object [this.count] ;

this.root.toArrayNode();

return this.returnData ;

}

@Override

public E get(int index){

if(index >= this.count){

throw new ArrayIndexOutOfBoundsException("指定索引不在范围之内");

}else{

this.foot = 0 ;

return this.root.getNode(index) ;

}

}

@Override

public void set(int index, E data){

if(index >= this.count){

throw new ArrayIndexOutOfBoundsException("指定索引不在范围之内");

}else{

this.foot = 0 ;

this.root.setNode(index,data) ;

}

}

@Override

public boolean contains(E data){

if(data == null){

return false ;

}else{

return this.root.containsNode(data) ;

}

}

@Override

public void remove(E data){

if(this.contains(data)){

if(this.root.data.equals(data)){

this.root = this.root.next ;

}else{

this.root.next.removeNode(this.root, data) ;

}

this.count -- ;

}

}

//-------------------以上为接口子类,以下为内部类---------------------------

private class Node{//创建内部类用于实现引用关系的处理

private E data ;//用于节点保存数据

private Node next ;//用于节点的引用关系

public Node(E data){//创建节点是保存数据

this.data = data ;

}

//保存新的节点数据

public void addNode(Node newNode){

if(this.next == null){

this.next = newNode ;

}else{

this.next.addNode(newNode) ;

}

}

public void toArrayNode(){

LinkImpl.this.returnData[LinkImpl.this.foot ++] = this.data ;

if(this.next != null){

this.next.toArrayNode() ;

}

}

public E getNode(int index){

if(LinkImpl.this.foot ++ == index){

return this.data ;

}else{

return this.next.getNode(index) ;

}

}

public void setNode(int index, E data){

if(LinkImpl.this.foot ++ == index){

this.data = data ;

}else{

this.next.setNode(index,data) ;

}

}

public boolean containsNode(E data){

if(this.data.equals(data)){

return true ;

}else{

if(this.next == null){

return false ;

}else{

return this.next.containsNode(data) ;

}

}

}

public void removeNode(Node previous, E data){

if(this.data.equals(data)){

previous.next = this.next ;

}else{

if(this.next != null){

this.next.removeNode(this, data) ;

}

}

}

}

}

public class LinkDemo{

public static void main(String args[]){

ILink link = new LinkImpl () ;

link.add("Hello");

link.add("World");

link.add("Allan");

link.add("Tom");

System.out.println(link.getLength()) ;

System.out.println(link.isEmpty()) ;

link.remove("Tom") ;

Object [] results = link.toArray() ;

for(Object obj : results){

System.out.println(obj) ;

}

link.set(2,"你好!!!") ;

System.out.println(link.get(2));

System.out.println(link.contains("你好!!!"));

System.out.println(link.contains("2212"));

}

}

java汉字转化accic_Java自主学习贴相关推荐

  1. java 中文分词转拼音_Java实现将汉字转化为汉语拼音的方法

    本文实例讲述了Java实现将汉字转化为汉语拼音的方法.分享给大家供大家参考,具体如下: 网上乱转,偶然看到一个很有意思的小工具,名字叫pinyin4j,可以把汉字转换为汉语拼音,利用他的话再配合上lu ...

  2. java如何把汉字转换成机内码_java语言如何将汉字转化成五笔

    java语言如何将汉字转化成五笔 [2021-01-31 08:32:59]  简介: php将汉字转ascii的方法:首先创建一个php示例文件:然后通过封装好的"public funct ...

  3. java将汉字转化为拼音

    在日常的开发中,可能需要将汉字转化为拼音,例如想要某些城市的开头拼音大写字母作为城市的简称,全国有几百个城市,如果需要一个一个自己拼那太麻烦了,在 Java 中,有人开发这样一个工具. 下面看一下如何 ...

  4. java中输入汉字转化为拼音

    置顶:https://github.com/java-aodeng/hope 老铁,来个star import java.util.Iterator;   import java.util.Linke ...

  5. java实现Excel文件解析---apache POI以及把汉字转化为拼音

    java实现Excel文件解析----apache  POI以及把汉字转化为拼音 1.POI简介 Apache POI是Apache软件基金会的开放源码函式库,POI提供给Java程序对Microso ...

  6. java 实现中文转化为拼音代码 汉字转化为拼音源码分享

    /*** 把汉字转化为拼音集合* @param src* @return Set<String>*/public static Set<String> getPinyin(St ...

  7. Java汉字转拼音库,Pinyin4j

    pinyin4j是一个支持将简体和繁体中文转换到成拼音的Java开源类库,作者是Li Min (xmlerlimin@gmail.com).以下是一些具体的介绍和使用方式.         1.pin ...

  8. java 汉字转拼音缩写_汉字转拼音 java 工具类

    package qing.huang; import java.io.UnsupportedEncodingException; import java.util.ArrayList; import ...

  9. 记录一下:Java 汉字获取拼音或首字母工具类

    记录一下:Java 汉字获取拼音或首字母工具类 Maven依赖配置 Java代码 本文主要记录一下在Java中,如何将字符串中的中文转化为拼音,获取汉字串拼音首字母,获取汉字串拼音的工具类,以及相关的 ...

最新文章

  1. AGX Xavier CAN调试
  2. MySQL Cluster(MySQL 集群) 初试
  3. 每日一皮:PM说要为客户着想,他们买车干嘛?最终归宿就是回家啊!
  4. Fast R-CNN: 我变快了,也变强了!
  5. JavaScript的10种跨域共享的方法
  6. Spring Boot基础
  7. java商城答辩_java网上商城系统毕业设计答辩.ppt
  8. 学习游戏服务器编程进阶篇之全球同服技术架构
  9. web自动化:web控件交互操作/多窗口处理/网页frame
  10. 制作纯净的U盘启动盘(避免纯净系统安装后却内置垃圾软件)
  11. 【python量化】用时间卷积神经网络(TCN)进行股价预测
  12. 软件工程师必须掌握的知识结构
  13. ValueError: A 0.7-series setuptools cannot be installed with distribute.
  14. 《金融学》笔记 第五章 金融市场
  15. VirtualBox加载光盘的镜像文件
  16. 为什么高一的学生都说数学难?
  17. 2017年12月5日 17:14:03
  18. Leetcode May Challenge - 05/07: Cousins in Binary Tree(Python)
  19. 10以内的分解与组成怎么教_“10以内数的组成”训练方法
  20. 小米note连接手机,root

热门文章

  1. 打印python包含汉字报SyntaxError: Non-ASCII character '\xe4' in file
  2. 动态规划 最长上升子序列
  3. LeetCode--171--Excel表列序号
  4. VMware安装Centos7后有线线缆被拔出
  5. 如何脱离SDK,使用DW5.5和phonegap以及JQMobile搭建开发环境
  6. 魔兽世界客户端数据研究(三)
  7. 新手学html 第一节:html简介
  8. 工作中常用的但是又容易忽略的问题
  9. 前端开发注意事项(HTML与CSS进阶)
  10. 使用postman测试接口