

题目如上图所示 ,代码如下:
#include <iostream>
#include <string>
using namespace std;
struct linknode{
char data;
linknode * next;
};
int main() {
linknode* head = NULL;
linknode* tail = NULL;
string chs;
cin>>chs;
for(int i=0;i<chs.size();i++){
linknode* newNode=(linknode*)malloc(sizeof(linknode));
newNode->data=chs[i];
newNode->next=NULL;
if(tail==NULL)
head=tail=newNode;
else
{
tail->next=newNode;
tail=newNode;
}
}
if(head==NULL)
return 0;
linknode *q=head,*pre=NULL;
while(q && q->next)
{
linknode *p1=q,*p2=q->next;
q=p2->next;
p1->next=p2->next;
p2->next=p1;
if (pre == NULL)
head = p2;
else
pre->next = p2;
pre = p1;
}
while(head!=NULL){
cout<<head->data;
head=head->next;
}
cout << endl;
return 0;
}
积累积累。
1414

被折叠的 条评论
为什么被折叠?



