08/11/10 21:12:16
>>535
#include<stdio.h>
#include<stdlib.h>
struct cell {
int data;
struct cell *next;
};
int main(void){
int num;
struct cell *new, *start, *p1, *p2;
new = start = p1 = p2 = NULL;
while (1) {
scanf("%d", &num);
if (num == -1) break;
new = (struct cell *) malloc(sizeof(start));
if (new == NULL) { return 1; }
new->data = num;
new->next = NULL;
for(p1=start,p2=NULL; (p1) && new->data > p1->data; p2=p1, p1=p1->next);
if(p2){
p2->next = new;
new->next = p1;
}else{
new->next = start;
start = new;
}
}
for (p1=start; (p1); p1=p1->next) { printf("%d\n", p1->data); }
return 0;
}