/* allocates a new node and links it to the list -- at the end */
int append_node(List **list, char *content)
{
  List *new_node;
  List *last;

  new_node = create_new_node(content);
  if (new_node == NULL)
    {
      return (1);
    }
  new_node->next = NULL;

  /* if this is the first node: */
  if (*list == NULL)
    {
      *list = new_node;
    }
  else
    {
      /* find the last node and designate the new node to follow */
      last = find_last_node(list);
      last->next = new_node;
    }

  return (0);
}
示例#2
0
int add_node(List **list, char *str){
  List *last_node;
  List *node;

  node = malloc(sizeof(List)); /* Allocate memory for new node */
  if (node == NULL)
    return 1;

  node->str = copy_string(str); /* Add copy of string to node */
  if (node->str == NULL) {
    return 1;
  }
  node->next = NULL;

  if (*list == NULL) {
    *list = node; /* If list is NULL, sets equal to new node */
  } else {
    last_node = find_last_node(*list); /* Appends the new node to the end */
    last_node->next = node;
  }

  return 0; /* Return successful */
}
示例#3
0
 inline size_t find_owned_nodes(const vm::process_id id) const
 {
    return find_last_node(id) - find_first_node(id);
 }
示例#4
0
List *find_last_node(List *list){
  /* Recurses to find the last node in list */
  if(list->next == NULL)
    return list;
  return find_last_node(list->next);
}