Exemplo n.º 1
0
   void list_copy(const node* source_ptr, node*& head_ptr,
                  node*& tail_ptr)
   {
      head_ptr = NULL;
      tail_ptr = NULL;

      // Handle the case of the empty list.
      if (source_ptr == NULL)
         return;

      // Make the head node for the newly created list, and put data
      // in it.
      list_head_insert( head_ptr, source_ptr->data() );
      tail_ptr = head_ptr;

      // Copy the rest of the nodes one at a time, adding at the tail
      // of new list.
      source_ptr = source_ptr->link();
      while (source_ptr != NULL)
      {
         list_insert( tail_ptr, source_ptr->data() );
         tail_ptr = tail_ptr->link();
         source_ptr = source_ptr->link();
      }
   }
Exemplo n.º 2
0
void list_piece(Node* start_ptr, Node* end_ptr, Node*& head_ptr, Node*& tail_ptr)
// Library facilities used: stdlib.h
{
    head_ptr = NULL;
    tail_ptr = NULL;

    // Handle the case of the empty list
    if (start_ptr == NULL)
        return;
    
    // Make the head node for the newly created list, and put data in it
    list_head_insert(head_ptr, start_ptr->data);
    tail_ptr = head_ptr;
    if (start_ptr == end_ptr)
        return;
    
    // Copy the rest of the nodes one at a time, adding at the tail of new list
    for (start_ptr = start_ptr->link; start_ptr != NULL; start_ptr = start_ptr->link)
    {
        list_insert(tail_ptr, start_ptr->data);
        tail_ptr = tail_ptr->link;
        if (start_ptr == end_ptr) 
            return;
    }
}
int exynos_param_register(struct exynos_camera *exynos_camera, char *key,
	union exynos_param_data data, enum exynos_param_type type)
{
	struct list_head *list_end;
	struct list_head *list;
	struct exynos_param *param;

	if (exynos_camera == NULL || key == NULL)
		return -EINVAL;

	param = (struct exynos_param *) calloc(1, sizeof(struct exynos_param));
	if (param == NULL)
		return -ENOMEM;

	param->key = strdup(key);
	switch (type) {
		case EXYNOS_PARAM_INT:
			param->data.integer = data.integer;
			break;
		case EXYNOS_PARAM_FLOAT:
			param->data.floating = data.floating;
			break;
		case EXYNOS_PARAM_STRING:
			param->data.string = strdup(data.string);
			break;
		default:
			ALOGE("%s: Invalid type", __func__);
			goto error;
	}
	param->type = type;

	list_end = (struct list_head *) exynos_camera->params;
	while (list_end != NULL && list_end->next != NULL)
		list_end = list_end->next;

	list = (struct list_head *) param;
	list_head_insert(list, list_end, NULL);

	if (exynos_camera->params == NULL)
		exynos_camera->params = param;

	return 0;

error:
	if (param != NULL) {
		if (param->key != NULL)
			free(param->key);

		free(param);
	}

	return -1;
}
Exemplo n.º 4
0
void list_copy(node * source_ptr, node * & head_ptr,
               node * & tail_ptr)
{
    head_ptr = tail_ptr = NULL;
    if (source_ptr == NULL)
        return;

    list_head_insert(head_ptr, source_ptr->data());
    tail_ptr = head_ptr;

    for (source_ptr = source_ptr->link();
         source_ptr != NULL;
         source_ptr = source_ptr->link())
    {
        list_insert(tail_ptr, source_ptr->data());
        tail_ptr = tail_ptr->link();
    }
}
Exemplo n.º 5
0
	BigInteger::BigInteger(string input)	//this constructor creates a BigInteger using a string
	{strnumber = input;						//saves string as strnumber
	head_ptr = NULL;						//initializes head_ptr to NULL
	int digits = input.length();			//calculates number of nodes
	int nodes = ceil(digits/3);
	many_nodes = nodes;
	int length = input.length();

	while (length > 0)							//converts characters to integers and stores them
		{int digit1 = (input[length -1])- '0';	//in the linked list three at a time
		int digit2 = ((input[length-2])-'0') * 10;
		int digit3 = ((input[length-3]) - '0') * 100;
		int mynumber = digit1 + digit2 + digit3;
		list_head_insert(head_ptr, mynumber);
		length = length - 3;
		}
	
	}
Exemplo n.º 6
0
void smatrix::add_entry(const entry &e)
{
    assert(e.r < nrows && e.c < ncols);

    list_head_insert(head_ptr, e);
    for (node *cursor = head_ptr; cursor->link() != NULL; cursor = cursor->link())
    {
        entry e1 = cursor->data();
        entry e2 = cursor->link()->data();

        if (e1 == e2)
        {
            list_remove(cursor);
            return;
        }

        if (e1 < e2)
            return;

        cursor->set_data(e2);
        cursor->link()->set_data(e1);
    }
}
Exemplo n.º 7
0
void list_copy_reverse(node *source_ptr, node *&copy_ptr)
{
    copy_ptr = NULL;
    for (node * p = source_ptr; p != NULL; p = p->link())
        list_head_insert(copy_ptr, p->data());
}
Exemplo n.º 8
0
    void bag::insert(const value_type& entry) {
		list_head_insert(head_ptr, entry);
		++many_nodes;
    }