新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     W3CHINA.ORG讨论区     计算机科学论坛     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> 研友的交流园地,讨论关于计算机考研的方方面面。
    [返回] 中文XML论坛 - 专业的XML技术讨论区计算机理论与工程『 计算机考研交流 』 → [讨论]快速排序算法 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 3368 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: [讨论]快速排序算法 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     hongjunli 帅哥哟,离线,有人找我吗?魔羯座1978-1-20
      
      
      威望:5
      头衔:为振兴论坛而努力!
      等级:研二(中了一篇WWWC Poster)(版主)
      文章:808
      积分:7964
      门派:IEEE.ORG.CN
      注册:2006/3/9

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给hongjunli发送一个短消息 把hongjunli加入好友 查看hongjunli的个人资料 搜索hongjunli在『 计算机考研交流 』 的所有贴子 引用回复这个贴子 回复这个贴子 查看hongjunli的博客楼主
    发贴心情 [讨论]快速排序算法

    若待排序列用单链表表示(不带头接点)试给出起快速排序算法(要求以首元接点的数据域的关键字值为轴元素,先用文字写出实现的基本思想,再用c语言写出算法)


    大家老讨论一下,看看这个算法如何实现啊,如果用双链表的话,比较好实现,但是现在是要求单链表来实现,大家来讨论一下,看看用单链表如何来实现这个算法啊?


       收藏   分享  
    顶(0)
      




    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2006/9/22 16:05:00
     
     Logician 帅哥哟,离线,有人找我吗?天蝎座1984-10-28
      
      
      威望:9
      头衔:逻辑爱好者
      等级:研三(收到IBM CRL的Offer了)(版主)
      文章:1219
      积分:10357
      门派:IEEE.ORG.CN
      注册:2005/3/12

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给Logician发送一个短消息 把Logician加入好友 查看Logician的个人资料 搜索Logician在『 计算机考研交流 』 的所有贴子 点击这里发送电邮给Logician  访问Logician的主页 引用回复这个贴子 回复这个贴子 查看Logician的博客2
    发贴心情 
    似乎比较简单啊。
    只要逐一把首节点的关键字与之后节点的关键字比较,小的串在一个链表里,大的串在另一个链表里,最后把首节点接在小链表的末尾,大链表接后面就可以了。

    ----------------------------------------------
    Three passions, simple but overwhelmingly strong, 
    have governed my life: the longing for love, the
    search for knowledge, and unbearable pity for the
    suffering of mankind.
                                - Bertrand Russell

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2006/9/22 17:20:00
     
     Logician 帅哥哟,离线,有人找我吗?天蝎座1984-10-28
      
      
      威望:9
      头衔:逻辑爱好者
      等级:研三(收到IBM CRL的Offer了)(版主)
      文章:1219
      积分:10357
      门派:IEEE.ORG.CN
      注册:2005/3/12

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给Logician发送一个短消息 把Logician加入好友 查看Logician的个人资料 搜索Logician在『 计算机考研交流 』 的所有贴子 点击这里发送电邮给Logician  访问Logician的主页 引用回复这个贴子 回复这个贴子 查看Logician的博客3
    发贴心情 
    #include <iostream>
    #include <time.h>
    using namespace std;

    template <class KeyType, class DataType>
    class SLNode
    {
    public:
     KeyType key;
     DataType data;
     SLNode<KeyType,DataType> *next;
    };

    template <class KeyType, class DataType>
    SLNode<KeyType,DataType> *QuickSort(SLNode<KeyType,DataType> *first)
    {
     KeyType firstKey;
     SLNode<KeyType,DataType> *small_first, *small_last, *big_first, *big_last, *cur;
     if(first==NULL)
      return NULL;
     else
     {
      small_first=NULL;
      big_first=NULL;
      small_last=NULL;
      big_last=NULL;
      firstKey=first->key;
      for(cur=first->next;cur!=NULL;cur=cur->next)
      {
       if(cur->key<firstKey)
       {
        if(small_first==NULL)
        {
         small_first=cur;
         small_last=cur;
        }
        else
        {
         small_last->next=cur;
         small_last=cur;
        }
       }
       else
       {
        if(big_first==NULL)
        {
         big_first=cur;
         big_last=cur;
        }
        else
        {
         big_last->next=cur;
         big_last=cur;
        }

       }
      }
      if(small_last!=NULL)
       small_last->next=NULL;
      if(big_last!=NULL)
       big_last->next=NULL;
      small_first = QuickSort(small_first);
      big_first = QuickSort(big_first);
      first->next=big_first;
      if(small_first!=NULL)
      {
       for(cur=small_first;cur->next!=NULL;cur=cur->next);
       cur->next=first;
       first=small_first;
      }
      return first;
     }
    }

    void main()
    {
     int i;
     SLNode<int,int> *first, *last, *p;
     srand((unsigned)time( NULL ));
     first=NULL;
     for(i=1;i<=100;i++)
     {
      p=new SLNode<int,int>;
      p->data=i;
      p->key=rand();
      if(first==NULL)
      {
       first=p;
       last=p;
      }
      else
      {
       last->next=p;
       last=p;
      }
     }
     last->next=NULL;
     for(p=first;p!=NULL;p=p->next)
      cout<<p->key<<","<<p->data<<"; ";
     cout<<endl<<endl;
     first = QuickSort(first);
     for(p=first;p!=NULL;p=p->next)
      cout<<p->key<<","<<p->data<<"; ";
     cout<<endl;
    }

    ----------------------------------------------
    Three passions, simple but overwhelmingly strong, 
    have governed my life: the longing for love, the
    search for knowledge, and unbearable pity for the
    suffering of mankind.
                                - Bertrand Russell

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2006/9/22 17:58:00
     
     Supremgoooo 帅哥哟,离线,有人找我吗?
      
      
      等级:大四下学期(考上研究生啦!)
      文章:201
      积分:1872
      门派:XML.ORG.CN
      注册:2006/4/9

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给Supremgoooo发送一个短消息 把Supremgoooo加入好友 查看Supremgoooo的个人资料 搜索Supremgoooo在『 计算机考研交流 』 的所有贴子 引用回复这个贴子 回复这个贴子 查看Supremgoooo的博客4
    发贴心情 
    对!
    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2006/9/22 23:09:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 计算机考研交流 』 的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2026/4/5 16:55:42

    本主题贴数4,分页: [1]

    管理选项修改tag | 锁定 | 解锁 | 提升 | 删除 | 移动 | 固顶 | 总固顶 | 奖励 | 惩罚 | 发布公告
    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    78.125ms