package sort;
class ComliexListNode{
int value;
ComliexListNode next;
ComliexListNode sibling;
public int getValue() {
return value;
}
public void setValue(int value) {
this.value = value;
}
public ComliexListNode getNext() {
return next;
}
public void setNext(ComliexListNode next) {
this.next = next;
}
public ComliexListNode getSibling() {
return sibling;
}
public void setSibling(ComliexListNode sibling) {
this.sibling = sibling;
}
}
public class Test35 {
public static void main(String[] args) {
ComliexListNode head=new ComliexListNode();
head.value=10;
head.sibling=head;
CloneNodes(head);
ConnSiblingNodes(head);
ReconnectNode(head);
}
private static ComliexListNode ReconnectNode(ComliexListNode head) {
//ComliexListNode point=null;
//ComliexListNode phead=null;
ComliexListNode pclone=null;
ComliexListNode cloneHead=null;
// TODO Auto-generated method stub
if(head!=null){
pclone=head.next;
cloneHead=pclone;
}
while(pclone.next!=null){
pclone.next=pclone.next.next;
pclone=pclone.next;
}
return cloneHead;
}
private static void ConnSiblingNodes(ComliexListNode head) {
// TODO Auto-generated method stub
ComliexListNode temp1=head;
ComliexListNode temp2=head.next;
while (temp1!=null&&temp2!=null) {
temp2.sibling=temp1.sibling.next;
temp2=temp1.next;
if(temp2!=null) temp1=temp2.next;
}
}
public static void CloneNodes(ComliexListNode head){//复制节点、相当于在每个节点后添加一个复制节点
//并用指针相连
ComliexListNode point=head;
while (point!=null) {
ComliexListNode temp=new ComliexListNode();
temp.value=point.value;
temp.next=point.next;
point.next=temp;
point=point.next.next;
}
}
}
783

被折叠的 条评论
为什么被折叠?



