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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java循环单链表比较相等_java的循环单链表

發布時間:2023/12/10 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java循环单链表比较相等_java的循环单链表 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

packageclink;//循環單鏈表

public classTestClink {public static voidmain(String[] args) {//TODO Auto-generated method stub

Clink t1 = newClink();for(int i = 0;i<9;i++){

t1.insertHead(i);

}

t1.show();int len=t1.getlength();

System.out.println(len);

System.out.println("---");

t1.insertTail(5);

t1.insertTail(5);

t1.show();

System.out.println("---");

t1.delete(5);

t1.show();

}

}classClink{classEntry{intdata;

Entry next;publicEntry(){this.data=-1;this.next=null;

}public Entry(intdata){this.data=data;this.next=null;

}

}private Entry head=null;publicClink(){this.head=newEntry();this.head.next=this.head;

}

//頭插法public void insertHead(intval){

Entry entry=newEntry(val);

entry.next=this.head.next;this.head.next=entry;

}

//尾插法public void insertTail(intval){

Entry cur=this.head;//定義一個節點用來尋找鏈表的尾結點

while(cur.next!=this.head){

cur=cur.next;

}

Entry entry=new Entry(val);//定義要插入的節點

entry.next=cur.next;

cur.next=entry;

}public booleanisEmpty(){

Entry cur=this.head;if(cur.next!=this.head){return false;

}return true;

}

刪除值為5的所有節點public boolean delete(intval){//此時刪除5

Entry prev=this.head;

Entry cur=this.head.next;if(isEmpty()){return false;

}while(cur!=this.head){if(cur.data==val){

prev.next=cur.next;

cur=prev.next;

}else{

prev=cur;

cur=cur.next;

}

}return true;

}/*public void delete(int val){

Entry prev=this.head;

Entry cur=this.head.next;

while(cur!=this.head){

if(cur.data==val){

prev.next=cur.next;

cur=prev.next;

}else{

prev=cur;

cur=cur.next;

}

}

}*/

public intgetlength(){

Entry cur=this.head;int len=0;while(cur.next!=head){

len++;

cur=cur.next;

}returnlen;

}public voidshow(){

Entry cur=this.head.next;while(cur!=this.head){

System.out.println(cur.data+"data");

cur=cur.next;

}

System.out.println();

}

}

總結

以上是生活随笔為你收集整理的java循环单链表比较相等_java的循环单链表的全部內容,希望文章能夠幫你解決所遇到的問題。

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