日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

java汉字转化accic_Java自主学习贴

發布時間:2023/12/20 java 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java汉字转化accic_Java自主学习贴 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

該樓層疑似違規已被系統折疊?隱藏此樓查看此樓

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自主学习贴的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。