From 425b724070835b83ef5c20c422595f7d06272568 Mon Sep 17 00:00:00 2001 From: quanxing Date: Sun, 18 Nov 2018 17:17:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=9B=9E=E6=96=87=E5=AD=97?= =?UTF-8?q?=E7=AC=A6=E4=B8=B2=E4=BB=A3=E7=A0=81bug=EF=BC=8C=E8=AF=B7?= =?UTF-8?q?=E6=8C=87=E6=95=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- java/06_linkedlist/SinglyLinkedList.java | 38 +++++++++++++----------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/java/06_linkedlist/SinglyLinkedList.java b/java/06_linkedlist/SinglyLinkedList.java index cf3d1545..c6d36e2f 100644 --- a/java/06_linkedlist/SinglyLinkedList.java +++ b/java/06_linkedlist/SinglyLinkedList.java @@ -218,15 +218,15 @@ public boolean palindrome(){ Node rightLink = null; if(q.next == null){ // p 一定为整个链表的中点,且节点数目为奇数 - leftLink = inverseLinkList(p); + rightLink = p.next; + leftLink = inverseLinkList(p).next; System.out.println("左边第一个节点"+leftLink.data); - System.out.println("右边第一个节点"+p.next.data); - rightLink = p; + System.out.println("右边第一个节点"+rightLink.data); }else{ //p q 均为中点 + rightLink = p.next; leftLink = inverseLinkList(p); - rightLink = q; } return TFResult(leftLink, rightLink); @@ -306,29 +306,31 @@ public static void main(String[]args){ SinglyLinkedList link = new SinglyLinkedList(); System.out.println("hello"); //int data[] = {1}; + //int data[] = {1,2}; //int data[] = {1,2,3,1}; - int data[] = {1,2,4,5}; + //int data[] = {1,2,5}; //int data[] = {1,2,2,1}; - //int data[] = {1,2,5,2,1}; + // int data[] = {1,2,5,2,1}; + int data[] = {1,2,5,3,1}; for(int i =0; i < data.length; i++){ //link.insertToHead(data[i]); link.insertTail(data[i]); } + // link.printAll(); + // Node p = link.inverseLinkList_head(link.head); + // while(p != null){ + // System.out.println("aa"+p.data); + // p = p.next; + // } + + System.out.println("打印原始:"); link.printAll(); - Node p = link.inverseLinkList_head(link.head); - while(p != null){ - System.out.println("aa"+p.data); - p = p.next; + if (link.palindrome()){ + System.out.println("回文"); + }else{ + System.out.println("不是回文"); } - - //System.out.println("打印原始:"); - //link.printAll(); - //if (link.palindrome()){ - // System.out.println("回文"); - //}else{ - // System.out.println("不是回文"); - //} } }