第10回 宿題に関して(6/26)

● 再提出者・未提出者は、以下の処理の様子を図説すること。

#include "numlist.h"

main() {
  Node *l1, *p, *q;
  int num;

  l1 = (Node *)malloc(sizeof(Node));
  l1->next = NULL;
  /* l1->val は不定でよい */

  num = 5;
  for( p = l1; (p->next != NULL) && (p->next->val < num); p=p->next ) {}
  q = list_make_node(num);
  q->next = p->next;
  p->next = q;

  num = 8;
  for( p = l1; (p->next != NULL) && (p->next->val < num); p=p->next ) {}
  q = list_make_node(num);
  q->next = p->next;
  p->next = q;

  num = 7;
  for( p = l1; (p->next != NULL) && (p->next->val < num); p=p->next ) {}
  q = list_make_node(num);
  q->next = p->next;
  p->next = q;

  num = 10;
  for( p = l1; (p->next != NULL) && (p->next->val < num); p=p->next ) {}
  q = list_make_node(num);
  q->next = p->next;
  p->next = q;

  num = 9;
  for( p = l1; (p->next != NULL) && (p->next->val < num); p=p->next ) {}
  q = list_make_node(num);
  q->next = p->next;
  p->next = q;

  list_print(l1);
}

(c) Masato TOKUHISA, 2003, June.25