中软国际笔试题汇总

#include 
//#include


/*void fun(const char * str, int len)
{
int i = 0;
int j = len - 1;
while (i < j)
{
if(str[i]==str[j])
{
i++;
j--;
}
else
{
printf("NO\n");
return;
}
}
printf("YES\n");
return;
}
int strcmp(const char *src,const char *dst) 

    int i = 0; 
    while(src[i] && dst[i]) 
        { 
        if(src[i] > dst[i]) 
            return 1; 
            else 
                if(src[i] < dst[i]) 
                    return -1; 
                    else 
                        i++;
if(src[i] == '\0' && dst[i] != '\0')
return -1;
else if (src[i] != '\0' && dst[i] == '\0')
{
return 1;
}
    } 
    return 0; 
}  */


int add(int * arr,int n)
{
/*int i;
int num = 0;
for(i=0;i {
num += arr[i];
}
return num;
*/
static int num = 0;
if(n-->0)
{
num += arr[n];
add(arr,n);
}
return num;
}
 
int main(int argc,char *argv[]) 

/*unsigned short a = 0x5;
unsigned int sum = 0;
while (a)
{
int i = 0;
int tmp = 1;
while (i++<4)
{
sum += (a&0x1)*tmp;
tmp *=10;
a = a>>1;
}
}
printf("%d\n",sum);
return 0;
char * str1 = "asdffdsa";
char * str2 = "asdfsa";
fun(str1,strlen(str1));
fun(str2,strlen(str2));
return 0;
char *str1 = "abd"; 
    char *str2 = "abd"; 
    printf("%d\n",strcmp(str2,str1)); 
    return 0; */


int arr[] = {1,2,3,4,5,6};
printf("%d\n",add(arr,5));


1、 Windows 下消息处理机制流程?sendmessagepostmessage的区别。

http://blog.csdn.net/npjocj/article/details/6611029

2、 不用库函数,实现Strcpy函数。

char * strcpy(char * strDest,const char * strSrc)
        {
                if ((strDest==NULL)||strSrc==NULL))                     
                   return NULL;    
                char * strDestCopy=strDest; 
                while ((*strDest++=*strSrc++)!='\0'); 
                return strDestCopy;
        }
3  设计双链表数据结构类:实现增加,浏览,删除,头删,尾删,头插,尾插;头删,尾删,头插,尾插需要考虑时间复杂度。

#include
using namespace std;
template
class list;
template
class node
{
friend class  list;
node(){}
node(T _date)
{
date=_date;
next=NULL;
front=NULL;
}
private:
T date;
node* next;
node* front;
};
template
class list
{
public:
class iterator
{
public:
iterator(){}
iterator(node*& _p)
{
p=_p;
}
iterator operator =(iterator it)
{
this->p = it.p;
return (*this);
}
bool operator ==(const iterator & it)
{
return (this->p == it.p);
}
bool operator !=(const iterator & it)
{
return (this->p != it.p);
}
T operator *()
{
return (p->date);
}
iterator operator ++(int i)
{
this->p = this->p->next;
return (*this);
}
private:
node* p;
};


list()
{
len=0;
head=new node();
head->next = NULL;
head->front = NULL;
}
iterator push_front(T _date)
{
curr = new node(_date);
if(head->next == NULL)
{
head->next = curr;
curr->front = head;
}
curr->next = head->next;
head->next->front = curr;
head->next = curr;
curr->front = head;
len++;
return iterator(curr);
}
iterator push_back(T _date)

curr = head;
while(curr->next != NULL)
{
curr = curr->next;
}
curr->next = new node(_date);
curr->next->front = curr;
len++;
return iterator(curr->next);
}
iterator begin()
{
return iterator(head->next);
}
iterator end()
{
curr = head;
while(curr->next!=NULL)
{
curr = curr->next;
}
return iterator(curr->next);
}
iterator find(const T & _date)
{
curr = head;
while(curr->date == _date)
{
curr = curr->next;
}
return iterator(curr);
}
T back()
{
curr = head;
while(curr->next!=NULL)
{
curr = curr->next;
}
return curr->p->date;
}
T front()
{
return head->next->date;
}
void clear()
{
delete head;
head = NULL;
}
int size()
{
return len;
}
iterator erase(iterator pos)
{
curr = head;
while(curr != pos.p)
{
curr = curr->next;
}
if(curr == NULL)
{
cout<<"can not find"< }
else
{
node* tmp = curr->next;
curr->next->front = curr->front;
curr->front->next = curr->next;
delete curr;
curr = NULL;
len--;
return iterator(tmp);
}
}
iterator erase(iterator start, iterator end)
{
node* tmp = head;
node* tmp2 = start.p;
curr = head;
while(curr != start.p)
{
curr = curr->next;
}
while(tmp != end.p)
{
tmp = tmp->next;
}
if(curr == NULL || tmp == NULL)
{
cout<<"can not find"< }
else
{
int i = 1;
while(tmp2 != end.p)
{
tmp2 = tmp2->next;
i++;
}
tmp->front = curr->front;
curr->front->next = tmp;
delete curr;
delete tmp->front;
curr = NULL;
tmp->front = NULL;
len = len - i;
return iterator(tmp);
}
}
iterator insert(iterator pos, const T value)
{
curr = head;
while(curr != pos.p)
{
curr = curr->next;
}
node* tmp = new node(value);
curr->front->next = tmp;
tmp->front = curr->front;
tmp->next = curr;
curr->front = tmp;
return iterator(tmp);
}
void sort()
{
int i=0;
while(i {
node *tmp = head;
node *tmp1 = head->next;
node *tmp2 = tmp1->next;
while(tmp2!=NULL)
{
if(tmp1->data>tmp2->data)
{
tmp->front = NULL;
tmp1->front = NULL;
tmp2->front = NULL;
tmp->next = tmp2;
tmp1->next = tmp2->next;
tmp2->next = tmp1;
tmp2->front = tmp;
tmp1->front =tmp2;
tmp = tmp2;
tmp2 = tmp1->next;
}
else
{
tmp = tmp1;
tmp1 = tmp2;
tmp2 = tmp2->next;
}
}
i++;
}
}
void insert(iterator pos, int num, const T value)
{
curr = head;
while(curr != pos.p)
{
curr = curr->next;
}
if(curr->next == NULL)
{
cout<<"can not find"< }
node* rt = NULL;
node* rear = NULL;
node* rhead = NULL;
int i;
for(i=0;i {
rt = new node(value);
if(i==0)
{
curr->front->next = rt;
rt->front = curr->front;
rear = rt;
rhead = rt;
}
rear->next = rt;
rt->front = rear;
rear = rt;
}
curr->front = rear;
rear->next = curr;
}
private:
int len;
node* head;
node* curr;
};
void show(list l)
{
list::iterator it;
for(it=l.begin();it!=l.end();it++)
{
cout<<*it< }
}
int main(int argc, char *argv[])
{
list l1;
l1.push_back(11);
l1.push_back(31);
l1.push_back(41);
l1.push_back(21);
l1.push_back(61);
l1.push_back(71);
l1.push_front(55);


list::iterator ret;
ret = 11.begin();
//l1.insert(ret,5,100);
show(l1);
return 0;
}


你可能感兴趣的:(中软国际笔试题汇总)