コード例 #1
0
ファイル: main.c プロジェクト: mpiehl/data_structures
void testLL() {

  int i;
  int storeUs[6] = {5,10,15,7,2,2};

	struct list_head *head = NULL;

	head=create_new_ll();

	printf("Is the list empty? %s\n",is_list_empty(head) ? "Yes" : "No");

  for(i=0; i<6; i++) {
    add_new_node_ll(head,storeUs[i]);
  }
	printf("The number 2 occurs: %d time(s)\n",find_elements_ll(head,2));
  print_out_ll(head);
  remove_node_ll(head,5);
  print_out_ll(head);
  remove_node_ll(head,7);
  print_out_ll(head);
	printf("Total Elements %d\n",total_elements_ll(head));
  remove_node_ll(head,2);
  print_out_ll(head);
	printf("Total Elements %d\n",total_elements_ll(head));
	printf("The number 2 occurs: %d time(s)\n",find_elements_ll(head,2));
	printf("Does the element 10 exist in the list: %s\n", \
					does_element_exist_ll(head,10) ? "Yes!" : "No");
	printf("Does the element 100 exist in the list: %s\n", \
					does_element_exist_ll(head,100) ? "Yes!" : "No");
	printf("Is the list empty? %s\n",is_list_empty(head) ? "Yes" : "No");

	free_ll(head);
}
コード例 #2
0
ファイル: list.c プロジェクト: axelhellman/Lager2.0
void insert_shelf(list *list, shelf *new_shelf)
{
  linked_list_node *new_node = create_new_ll(new_shelf);
  int amount = new_shelf -> amount;
  list -> total = list -> total + amount;

  linked_list_node *prev_node = NULL;
  linked_list_node *crnt_node = list -> ll_first;
   if (crnt_node == NULL)
    {
      list -> ll_first = new_node;
      list -> ll_last = new_node;
      return;
      }  
  
  while (true)
    {
      if (crnt_node == NULL)
	{
	  prev_node -> next_node = new_node;
	  list -> ll_last = new_node;
	  break;
	}
            
      int crnt_amount = get_shelf_amount2(crnt_node);
 
      if (crnt_amount <  amount && prev_node == NULL)
	{
	  list -> ll_first = new_node;
	  new_node -> next_node = crnt_node;
	  break;
	}
      else if (crnt_amount <  amount || crnt_amount == amount)
	{
	  prev_node -> next_node = new_node;
	  new_node -> next_node = crnt_node;
	  break;
	}
      else if (crnt_amount > amount)
	{
	  prev_node = crnt_node;
	  crnt_node = crnt_node -> next_node;
	}      
      else
	{
	  puts("something is wrong");
	}
     
    }
  return;
}