zoukankan      html  css  js  c++  java
  • 合并两个有序列表

    很多人都在寻找实习、找工作。看看的想法,根据守则手写这个问题。假设有仍处于真正的调试的最佳机会,还有很多细节还需要注意。不多说了,例如,下面的代码记录:

    	Node* Merge(Node *h1,Node *h2)
    	{
    		Node *head,*pCurrent,*head1,*head2;
    		head1 = h1;
    		head2 = h2;
    		if(head1==NULL)
    			return head2;
    		else if(head2==NULL)
    			return head1;		
    		
    		head = head1->value < head2->value ? head1 : head2;
    		if (head == head1)
    			head1=head1->next;
    		else 
    			head2=head2->next;
    		pCurrent = head;
    		while(head1!= NULL && head2!=NULL)
    		{
    			if(head1->value <= head2->value)
    			{	
    				pCurrent->next = head1;
    				pCurrent = pCurrent->next;
    				head1 = head1->next;
    				continue;
    			}
    			
    			if(head1->value > head2->value)
    			{
    				pCurrent->next =head2;
    				pCurrent = pCurrent->next;
    				head2 = head2->next;
    				continue;
    			}
    		}
    		if(head1==NULL)
    		{
    			pCurrent->next = head2;
    		}
    		else if(head2 == NULL)
    		{
    			pCurrent->next = head1;
    		}
    		return head;
    	};


    版权声明:本文博主原创文章。博客,未经同意不得转载。

  • 相关阅读:
    面向对象基础
    JS操作属性和样式
    表单验证
    form标签
    Dreamweaver网页设计代码大全
    最差项目展示
    CSS样式表
    while循环 do while循环 switch
    for循环
    穷举法
  • 原文地址:https://www.cnblogs.com/blfshiye/p/4829620.html
Copyright © 2011-2022 走看看