当前位置:才高文秘网>范文大全 > 公文范文 > 将两个递增链表合并成一个递减链表

将两个递增链表合并成一个递减链表

时间:2022-08-28 10:50:08 公文范文 来源:网友投稿

下面是小编为大家整理的将两个递增链表合并成一个递减链表,供大家参考。

将两个递增链表合并成一个递减链表

 

 #include "stdio. h" #include "stdlib. h" struct Node {int date;

  struct Node *next;

 } Node;

  goujian(struct Node *L)

 {

 struct Node *s, *p;

  int e; p=L;

  printf("输入数据:

 ") ;

  scanf("%d", &e) ;

  while(e!=-999)

 {s=(struct Node *) malloc(sizeof(struct Node) ) ;

 s->date=e;

  s->next=p->next;

 p->next=s;

 scanf("%d", &e) ;

 p=s; }

 }

  outline(struct Node *L)

 { struct Node *p;

  p=L->next;

  printf("输出数据:

 ") ;

  while(p!=NULL)

  {printf("%d ", p->date) ;

 p=p->next;

  }

  }

  hebing(struct Node *h1, struct Node *h2)

 {

 struct Node *q, *p, *r, *s;

  p=h1->next;

  q=h2->next;

  r=h1;

  r->next=NULL;

  while(p!=NULL&&q!=NULL)

  {if(p->date<=q->date)

  {

  s=p;

 p=p->next;

 s->next=r->next;

 r->next=s;

  }

  else

 {

  s=q;

  q=q->next;

  s->next=r->next;

  r->next=s;

  }

  if(q==NULL)

  {while(p!=NULL)

 {s=p;

 p=p->next;

 s->next=r->next;

 r->next=s; }

 }

  if(p==NULL)

 { while(q!=NULL)

  { s=q;

  q=q->next;

  s->next=r->next;

  r->next=s; }

 }

  }

 free(h2) ;

  }

  void main()

 { struct Node *h1, *h2;

  h1=(struct Node

 *) malloc(sizeof(struct Node) ) ;

  h2=(struct Node *) malloc(sizeof(struct Node) ) ;

  h1->next=NULL;

  h2->next=NULL;

  goujian(h1) ;

  goujian(h2) ;

  hebing(h1, h2) ;

  outline(h1) ;

 }

推荐访问:将两个递增链表合并成一个递减链表 链表 递减 递增

版权所有:才高文秘网 2017-2024 未经授权禁止复制或建立镜像[才高文秘网]所有资源完全免费共享

Powered by 才高文秘网 © All Rights Reserved.。备案号:沪ICP备17045173号-3