コード例 #1
0
ファイル: stdlib.c プロジェクト: AitibaGames/crema
/*
  Retrieves the element from a list of type double at the given index

  @param list The list to search
  @param idx The index of the element to be retrieved
  @return The element (double value) at the given index
*/
double double_list_retrieve(list_t * list, unsigned int idx)
{
  double *p = list_retrieve(list, idx);
  if (p != NULL)
    {
      fprintf(stderr, "ERROR: Retrieving out of bounds list element!\n");
      exit(-1);
    }
  return (double) *p;
}
コード例 #2
0
ファイル: stdlib.c プロジェクト: AitibaGames/crema
/*
  Retrieves the element from a list of type int at the given index

  @param list The list to search
  @param idx The index of the element to be retrieved
  @return The element (int value) at the given index
*/
int64_t int_list_retrieve(list_t * list, int64_t idx)
{
  int64_t *p = list_retrieve(list, idx);
  if (p == NULL)
    {
      fprintf(stderr, "ERROR: Retrieving out of bounds list element!\n");
      exit(-1);
    }
  return (int64_t) *p;
}
コード例 #3
0
ファイル: stdlib.c プロジェクト: AitibaGames/crema
/*
  Retrieves the character in the given string at the given index

  @param str The string to be operated on
  @param idx The index of the character to be returned
  @return The character found in string str at index idx
*/
char str_retrieve(string_t * str, unsigned int idx)
{
  char * p = list_retrieve(str, idx);
  if (p == NULL)
    {
      fprintf(stderr, "ERROR: Retrieving out of bounds list element!\n");
      exit(-1);
    }
  return (char) *p;
}
コード例 #4
0
ファイル: stdlib.c プロジェクト: AitibaGames/crema
/*
  Concatenates two lists together (string or array)

  @param list1 The first list
  @param list2 The second list to be concatenated onto the first list
*/
void list_concat(list_t * list1, list_t * list2)
{
  int i;
  if (list1->elem_sz != list2->elem_sz)
    {
      return;
    }
  list_resize(list1, list1->cap + list2->len);
  for (i = 0; i < list2->len; i++)
    {
      list_append(list1, list_retrieve(list2, i));
    }
}
コード例 #5
0
ファイル: test.c プロジェクト: royye62/mydemo
// 不带头节点的单向不循环链表
int main(void)
{
	int n;
	int indx;
	int key;
	struct node_t *head = NULL;

	while (1)
	{
	retry:
		printf("pls input n[-1 quit]: ");	
		my_scanf(goto retry, "%d", &n);

		if (-1 == n) 
			break;			

		list_append(&head, &n, sizeof(int));
	}

	list_traverse(head, print_int);
	putchar('\n');

	printf("test reverse list: \n");
	head = list_reverse(head);	
	list_traverse(head, print_int);
	putchar('\n');

	printf("test insert indx, pls input n: ");
	my_scanf( , "%d", &n);
	printf("pls input indx: ");
	my_scanf( , "%d", &indx);
	list_insert_indx(&head, &n, sizeof(int), indx);
	
	list_traverse(head, print_int);
	putchar('\n');

	printf("test restrieve, pls input indx: ");
	my_scanf(, "%d", &indx);
	list_retrieve(&head, &n, sizeof(int), indx);
	printf("the data you retrieve is %d\n", n);

	printf("test search, pls input key: ");
	my_scanf(, "%d", &key);
	indx = list_search(&head, &key, cmp_int);
	printf("the index you search is %d\n", indx);
	
	printf("test delby indx, pls input indx: ");
	my_scanf( , "%d", &indx);
	list_delby_indx(&head, indx, NULL);

	list_traverse(head, print_int);
	putchar('\n');

	printf("test delby key, pls input key: ");
	my_scanf( , "%d", &key);	
	list_delby_key(&head, &key, cmp_int, NULL);

	list_traverse(head, print_int);
	putchar('\n');

	list_free(head, NULL);

	return 0;
}