设为首页 加入收藏

TOP

C/C++面试问题分类大汇总(九)
2014-09-23 08:57:05 来源: 作者: 【 】 浏览:355
Tags:C/C 面试 问题 分类 汇总
iPivot]=a[j];

iPivot=j;

}

}

a[iPivot]=nPivot;

if(iPivot-ileft>1)

quick_sort(a,ileft,iPivot-1);

if(iright-iPivot>1)

quick_sort(a,iPivot+1,iright);

}

时间复杂度O(NlogN)

链表

单链表

双链表

循环链表

单链表逆置

void reverse(link *head)

{

    link *p, *s, *t;

    p = head;

    s = p->next;

    while(s->next!=NULL)

    {

        t = s->next;

        s->next = p;

        p = s;

        s = t;

    }

    s->next = p;

    head->next->next = NULL;    //尾指针置为空

    head->next = s;         //赋值到头指针后一位

}

链表合并

Node * Merge(Node *head1 , Node *head2)

{

if ( head1 == NULL)

return head2 ;

if ( head2 == NULL)

return head1 ;

Node *head = NULL ;

Node *p1 = NULL;

Node *p2 = NULL;

if ( head1->data < head2->data )

{

head = head1 ;

p1 = head1->next;

p2 = head2 ;

}else

{

head = head2 ;

p2 = head2->next ;

p1 = head1 ;

}

Node *pcurrent = head ;

while ( p1 != NULL && p2 != NULL)

{

if ( p1->data <= p2->data )

{

pcurrent->next = p1 ;

pcurrent = p1 ;

p1 = p1->next ;

}else

{

pcurrent->next = p2 ;

pcurrent = p2 ;

p2 = p2->next ;

}

}

if ( p1 != NULL )

pcurrent->next = p1 ;

if ( p2 != NULL )

pcurrent->next = p2 ;

return head ;

}

 

递归方式:

Node * MergeRecursive(Node *head1 , Node *head2)

{

if ( head1 == NULL )

return head2 ;

if ( head2 == NULL)

return head1 ;

Node *head = NULL ;

if ( head1->data < head2->data )

{

head = head1 ;

head->next = MergeRecursive(head1->next,head2);

}

else

{

head = head2 ;

head->next = MergeRecursive(head1,head2->next);

}

return head ;

}

写一个Singleton模式

#include<iostream>

using namespace std;

class Singleton

{

    private:

    static Singleton* _instance;

    protected:

    Singleton()

{

    cout<<”Singleton”<<endl;

}

  &nb

首页 上一页 6 7 8 9 10 11 下一页 尾页 9/11/11
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇C++ 数据结构、算法笔试题 下一篇关于C++ Traints——网易09年笔试..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: