c语言编程题,急求答案,在线等,谢谢!
1个回答
展开全部
#include <stdio.h>
#include <stdlib.h>
typedef struct _LinkNode {
int data;
struct _LinkNode* next;
} LinkNode;
int main() {
int n, i;
scanf("%d", &n);
LinkNode *head = (LinkNode*) malloc (sizeof(LinkNode)),
*tail = head;
head->data = 1;
for(i = 2; i <= 20; i++) {
LinkNode *p = (LinkNode*) malloc (sizeof(LinkNode));
p->data = i;
p->next = head;
tail->next = p;
tail = p;
}
for(i = 0; i < n; i++) {
int m, k;
scanf("%d", &m);
for(k = 0; k < m; k++) {
tail = head;
head = head->next;
}
printf("%d%c", head->data, (i < n - 1? ',' : '\n'));
head = head->next;
tail->next = head;
}
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询