数据结构—两个有序单链表的合并排序算法

viod merge(LNode *A,LNode *B){

         LNode *C;//新节点

         LNode *p = C;//辅助指针

         while(A->next !=null && B->next !=null){

              if(A->next->data > B->next->data){//A节点大

                  p->next=A->next;//A元素插入C

                 A=A=>next;

                 p=p->next;

       }else{

                 p->next=B->next;

                B=B->next;

                p=p->next;

}

                 if(A->next !=null){ //A中剩余元素

                        p->next=A->next;

                       A=A=>next;

                       p=p->next;

}

                if(B->next !=null){ //B中剩余元素

                     p->next=B->next;

                    B=B->next;

                    p=p->next;

}

}

}

你可能感兴趣的:(数据结构,排序算法,java)