#include
#include
typedef struct node
{
int val;
struct node *next;
}*linklist;
int main()
{
int m,n;scanf("%d %d",&m,&n);
linklist head,p,last;
head=NULL;int num;
for(int i=0;i<5;i++)
{
p=(linklist)malloc(sizeof(struct node));
scanf("%d",&(p->val));
if(head==NULL)
{
head=p;
last=head;
}
else
{
last->next=p;
last=p;
last->next=NULL;
}
}
int rp = 1;
linklist nhead = NULL,nlast;
linklist head2 = NULL,last2;
linklist head3 = NULL,last3;
int i;
while (rp++ < m) {
p = (linklist)malloc(sizeof(struct node));
p = head;
if (nhead == NULL) {
nhead = p;
nlast = nhead;
} else {
nlast->next = p;
nlast = p;
nlast->next = NULL;
}
head = head->next;
}
while (rp++ >= m && rp++ <= n) {
p = (linklist)malloc(sizeof(struct node));
p->next = head2;
head2 = p;
}
while (rp++>n) {
p = (linklist)malloc(sizeof(struct node));
if (head3 == NULL) {
head3 = p;
last3 = head3;
} else {
last3->next = p;
last3 = p;
last3->next = head3;
}
}
nlast->next=head2;
while (nhead) {
printf("%d",nhead->val);
nhead=nhead->next;
}
while(head3)
{
printf("%d",head3->val);
head3=head3->next;
}
}
牛客网BM1,创建三个新链表,1,3尾插法创建,2头插法创建,1,2链接,独立输出3.为什么没有结果