注册 登录
编程论坛 数据结构与算法

菜鸟问题:求单链表的冒泡排序算法(升序)!

igniz100 发布于 2011-03-04 18:35, 1238 次点击
请各位指教一下``
2 回复
#2
寒风中的细雨2011-03-04 22:58
链表会   和用数组差不多
#3
jkangj20112011-03-05 17:20
p1=p4=head;
    while(p1->next!=NULL){
        p2=p1->next;
        p3=p1;
        while(p2!=NULL){
            if(strcmp(p1->num,p2->num)>0){
                if(p1==head){
                    p3->next=p2->next;
                    head=p2;
                    p2->next=p1;
                    p1=head;
                    p2=p1->next;
                    p3=p1;
                }
                else {
                    p3->next=p2->next;
                    p4->next=p2;
                    p2->next=p1;
                    p1=p2;
                    p2=p1->next;
                    p3=p1;
                }
            }
            else {
                p3=p2;
                p2=p2->next;
            }
        }
        p4=p1;
        p1=p1->next;
    }
应该可以,你试试。
1