Skip to content

Commit

Permalink
Merge pull request wangzheng0822#160 from quanxing/master
Browse files Browse the repository at this point in the history
解决回文字符串实现错误
  • Loading branch information
wangzheng0822 authored Nov 23, 2018
2 parents af1f4a5 + 425b724 commit 81cea36
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions java/06_linkedlist/SinglyLinkedList.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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("不是回文");
//}
}

}

0 comments on commit 81cea36

Please sign in to comment.