设为首页 加入收藏

TOP

两个单向有序链表的归并算法
2014-11-23 17:56:39 】 浏览:9051
Tags:两个 单向 有序 归并 算法

  //递归算法


  NodePtr merge_lists(NodePtr& one_head,NodePtr& two_head)


  {


  NodePtr p1;


  p1=NULL;


  if(one_head == NULL && two_head == NULL)


  return p1;


  else if(one_head == NULL && two_head != NULL)


  return two_head;


  else if(one_head != NULL && two_head == NULL)


  return one_head;


  else


  {


  if(one_head->data <= two_head->data)


  {


  p1=one_head;


  p1->link = merge_lists(one_head->link,two_head);


  }


  else


  {


  p1=two_head;


  p1->link = merge_lists(one_head,two_head->link);


  }


  return p1;


  }


  }


  //迭代算法


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇C语言学习:dos如何转向windows 下一篇利用注册表修改桌面背景

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目