2014 微软校招笔试答案 编程题

上午参加完微软校招笔试,最后编程题的代码,仅供参考


#include

using namespace std;


struct Node
{
Node *next;
        int date;
};


void createlist(Node**head,int a[],int length)
{
(*head)=new Node;
(*head)->date=a[0];
(*head)->next=NULL;
Node *p=*head;
for(int i=1;i {
Node *q=new Node;
q->date=a[i];
q->next=NULL;
p->next=q;
p=q;

}

void showlist(Node *head)
{
while(head)
{
cout<date<<"----->";
head=head->next;


}
     cout< }




void Reoder(Node *head)
{
if(head ==NULL|| head->next==NULL ||head->next->next==NULL)
return;
Node *h=head,*q=NULL,*p=head->next;
while(p)
{


while(p->next)
{
q=p;
p=p->next;
}
     if(q)
{
p=h->next;
h->next=q->next;
q->next=NULL;
h->next->next=p;
h=p;
p=p->next;
q=NULL;
}
else
break;
}
}
void main()
{
int a[]={0,1,2};
Node *head=NULL;
createlist(&head,a,sizeof(a)/sizeof(int));
showlist(head);
Reoder(head);
showlist(head);


}

你可能感兴趣的:(笔试)