next up previous contents
Next: 末尾への追加 Up: リストの追加 Previous: リストの追加   Contents

先頭への追加

先頭への追加では、新規に追加される要素が先頭になり、 その次の要素が、以前の先頭要素になる。 以下、イメージ図(図9.4)、ならびにソースコード例を示す。

Figure 9.4: 先頭への追加イメージ
\begin{figure}
\begin{center}
\epsfile{file=fig9_4.eps,height=3.0cm}
\end{center}\end{figure}


list *add_to_head(list *head, void *val){
list *new_head;
new_head = (list *)malloc(sizeof(list));
new_head->val = val;
new_head->next = head;
return(new_head);
}



kojima hirohisa
2001-03-05