C/C++の宿題を片付けます 117代目at TECH
C/C++の宿題を片付けます 117代目 - 暇つぶし2ch541:デフォルトの名無しさん
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;
}


次ページ
続きを表示
1を表示
最新レス表示
レスジャンプ
類似スレ一覧
スレッドの検索
話題のニュース
おまかせリスト
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch