第1个回答 推荐于2017-09-27
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#define MAX_LEN 10
typedef struct _DATA_ {
int value;
_DATA_ *next;
}DATA;
void main()
{
int i;
char ch;
char str[MAX_LEN + 1];
DATA *pdata, *ptem, *ppre;
pdata = (DATA *)malloc(sizeof(DATA));
pdata->next = pdata;
// Input
while (1) {
for (i = 0; i < MAX_LEN; i++) {
ch = (char)getch();
printf("%c", ch);
if (ch == ' ')
break;
str[i] = ch;
}
i = atoi(str);
if (i == -1)
break;
ptem = (DATA *)malloc(sizeof(DATA));
ptem->value = i;
ptem->next = pdata->next;
pdata->next = ptem;
}
// Delete even numbers
ppre = pdata;
ptem = pdata->next;
while (ptem != pdata) {
if (ptem->value % 2 == 0) {
ppre->next = ptem->next;
free(ptem);
ptem = ppre->next;
} else {
ppre = ppre->next;
ptem = ptem->next;
}
}
// Output
printf("\n");
ptem = pdata->next;
while (ptem != pdata) {
printf("%d ", ptem->value);
ptem = ptem->next;
}
printf("\n");
}本回答被提问者采纳