struct CELL cell 1 cell 2 cell 3

  • Slides: 29
Download presentation

セルを作る(1) struct CELL *cell 1, *cell 2, *cell 3; cell 1 = (struct CELL

セルを作る(1) struct CELL *cell 1, *cell 2, *cell 3; cell 1 = (struct CELL *) malloc(sizeof(struct CELL)); メモリの内容 cell 3: cell 2: cell 1: ポインタ変数 cell 1, cell 2, cell 3 のための メモリ領域が確保 される。

セルを作る(4) struct CELL *cell 1, *cell 2, *cell 3; cell 1 =(struct CELL *)

セルを作る(4) struct CELL *cell 1, *cell 2, *cell 3; cell 1 =(struct CELL *) malloc(sizeof(struct CELL)); cell 1 ->data = 10; cell 1 ->next = NULL; cell 1: (data) (next) 10 NULL

セルを作る(4) struct CELL *cell 1, *cell 2, *cell 3; cell 1 =(struct CELL *)

セルを作る(4) struct CELL *cell 1, *cell 2, *cell 3; cell 1 =(struct CELL *) malloc(sizeof(struct CELL)); cell 1 ->data = 10; cell 1 ->next = NULL; 以降では、この様に簡 略化した図を用いて説 明をする。 cell 1: (data) (next) 10 NULL cell 1 (data) (next) 10 NULL

セルをつなげる (1) (data) (next) cell 1 root 10 NULL root = cell 1; cell

セルをつなげる (1) (data) (next) cell 1 root 10 NULL root = cell 1; cell 1 ->next=cell 2; cell 2 ->next=cell 3; (data) (next) cell 2 8 NULL (data) (next) cell 3 4 NULL cell 1の指し示すセル構 造体のアドレスをrootに 代入する。

セルをつなげる (2) (data) (next) cell 1 root 10 NULL root = cell 1; cell

セルをつなげる (2) (data) (next) cell 1 root 10 NULL root = cell 1; cell 1 ->next=cell 2; cell 2 ->next=cell 3; (data) (next) cell 2 8 NULL (data) (next) cell 3 4 NULL cell 2の指し示すセル構造 体のアドレスを cell 1 ->nextに代入する。

セルをつなげる (3) (data) (next) cell 1 root 10 root = cell 1; cell 1

セルをつなげる (3) (data) (next) cell 1 root 10 root = cell 1; cell 1 ->next=cell 2; cell 2 ->next=cell 3; (data) (next) cell 2 8 NULL (data) (next) cell 3 4 NULL cell 3の指し示すセル構造 体のアドレスを cell 2 ->nextに代入する。