【初心者歓迎】C/C++室 Ver.17【環境依存OK】
■ このスレッドは過去ログ倉庫に格納されています
0355デフォルトの名無しさん
2005/05/20(金) 00:09:42何ででしょうか?
#include <stdio.h>
#include <stdlib.h>
typedef struct node *link;
struct node {int item; link next;};
int main(int argc,char *argv[]) {
struct node heada,headb;
int i,N=atoi(argv[1]);
link t,u,x,a = &heada,b;
srand(1);
for(i=0,t=a;i<N;i++){
t->next = malloc(sizeof *t);
t = t->next; t->next = NULL;
t->item = rand() % 1000;
}
b = &headb; b->next = NULL;
for(t=a->next; t!=NULL;t=u){
u=t->next;
for(x=b;x->next!=NULL;x=x->next)
if(x->next->item > t->item) break;
t->next = x->next;
x->next = t;
}
}
■ このスレッドは過去ログ倉庫に格納されています