C言語なら、俺に聞け! <8>
■ このスレッドは過去ログ倉庫に格納されています
0513デフォルトの名無しさん
NGNGリスト構造で頭に新しいデータを入れるものですが
1と2のどちらの方がいいのでしょうか?
処理速度やメモリ使用量などが変わるのでしょうか?
struct LIST{
struct LIST *next_ptr;
int value;
};
main(){
struct LIST *top;
int i;
top=insert1(top, i); >1
insert2(&top, i); >2
}
struct LIST *insert1(struct LIST *ptr, int i){
struct *newcell;
newcell=(struct LIST *)malloc(sizeof(struct LIST));
newcell->next_ptr=ptr;
newcell->value=i;
return(newcell);
}
struct LIST insert2(struct LIST **ptr, int i){
struct LIST *newcell;
newcell=(struct LIST *)malloc(sizeof(struct LIST));
newcell->next_ptr=(*ptr);
newcell->value=i;
(*ptr)=newcell;
}
■ このスレッドは過去ログ倉庫に格納されています