示例#1
0
/**
 * @brief tests the push/pop functions of the list module
 * @return 0 if success
 * @return 1 if failture
 */
int test_list_push_pop()
{
    list_t *testList = list_create();

    int a = 12345;
    int b = 98765;
    int c = 54321;
    int d = 56789;
    int *resa, *resb, *resc, *resd;

    list_push_front(testList, &b);
    list_push_front(testList, &a);
    list_push_back(testList, &c);
    list_push_back(testList, &d);

    resa = list_pop_front(testList);
    resb = list_pop_front(testList);
    resd = list_pop_back(testList);
    resc = list_pop_back(testList);

    if(*resa != a || *resb != b || *resc != c || *resd != d)
    {
        printf("list push and pop front and back: failture\n");
        return 1;
    }

    list_destroy(testList);

    return 0;
}
示例#2
0
void
thread_cleanup_and_exit (int status) 
{
  printf ("%s: exit(%d)\n", thread_name (), status);
  /* close all open file descriptors */
  struct thread *t = thread_current ();
 
  struct list_elem *e;

  /* close all the files opened and
     free spaces allocated for the file list */
  while (!list_empty (&t->file_list))
    {
      e = list_pop_back (&t->file_list);
      struct file_elem *f_elem = list_entry (e, struct file_elem, elem);
      file_close (f_elem->file);
      free (f_elem);
    }

  /* free waited_children_list and children_list */
  while (!list_empty (&t->children_list))
    {
      e = list_pop_back (&t->children_list);
      struct child_elem *c_elem = list_entry (e, struct child_elem, elem);
      // free children from the global exit_list
      free_thread_from_exit_list (c_elem->pid);
      free (c_elem);
    }
  while (!list_empty (&t->waited_children_list))
    {
      e = list_pop_back (&t->waited_children_list);
      struct wait_child_elem *w_elem = list_entry (e, struct wait_child_elem, elem);
      free (w_elem);
    }

  add_thread_to_exited_list (t->tid, status);
  
  /* allow file write to executable */
  if (t->exec_file) 
    {
      file_allow_write (t->exec_file);
      file_close (t->exec_file);
    }

  /* release all the locks that have not already been released */
  while (!list_empty (&t->acquired_locks))
    {
      struct list_elem *e = list_front (&t->acquired_locks);
      struct lock *l = list_entry (e, struct lock, elem);
      lock_release (l);
    }
  /* wake parent up if its waiting on it */
  struct thread *parent = get_thread (thread_current ()->parent_id);
  if (parent)  {
    sema_up (&parent->waiting_on_child_exit_sema);
  }
  thread_exit ();
}
示例#3
0
文件: list.c 项目: yoones/hsn
void		list_pop_data(t_list *list, void *data)
{
  t_lnode	*w;

  if (list->size < 3)
    {
      if (list->head && list->head->data == data)
	list_pop_front(list);
      else if (list->tail && list->tail->data == data)
	list_pop_back(list);
    }
  else
    {
      for (w = list->head; w != NULL; w = w->next)
	{
	  if (w->data == data)
	    {
	      w->prev->next = w->next;
	      w->next->prev = w->prev;
	      list->size--;
	      free(w);
	      return ;
	    }
	}
    }
}
示例#4
0
int main() {
    List *list = list_create(sizeof(int));

    printf("List: ");
    int data = 1;
    list_push_back(list, &data);
    data = 3;
    list_push_back(list, &data);
    data = 5;
    list_push_back(list, &data);
    data = 0;
    list_push_back(list, &data);
    list_print(list, intPrinter);

    printf("\r\nRevd: ");
    list_reverse(list);
    list_print(list, intPrinter);

    data = -1;
    list_push_front(list, &data);
    printf("\r\nFron: ");
    list_print(list, intPrinter);

    list_pop_back(list, &data);
    printf("\r\nPopb: ");
    list_print(list, intPrinter);

    list_pop_front(list, &data);
    printf("\r\nPopf: ");
    list_print(list, intPrinter);

    printf("\r\n");

    return 0;
}
示例#5
0
文件: main.c 项目: sunneo/libs
int main ( int argc, char *argv[] )
{
   List* list = list_create ( sizeof ( int ),EqualInt );
   int t;
   ListNode* n;
   int i;
   for ( i=0; i<10; ++i )
      list_push_back ( list,createInt ( &t,rand() ) );
   /*list_foreach(list,printInt);*/
   ListIter iter = list_get_iter ( list );
   while ( list_iter_hasNext ( iter ) )
   {
      printInt ( list_iter_next ( iter ) );
   }
   printf ( "\n" );
   list_pop_back ( list );
   list_foreach ( list,incInt );
   list_foreach ( list,printInt );
   printf ( "\n" );
   n = list_find_first_node ( list,createInt ( &t,846930887 ) );
   list_erase_node ( list,n );
   list_foreach ( list,printInt );
   list_delete ( list );
   return 0;
}
示例#6
0
文件: main.c 项目: hbfhaapy/study
int 
main(int argc, char* argv[])
{
  int i;
  double* d;
  list_t l = list_create();

  list_test(l, list_push_front, list_pop_front, 45466, 0.001238);
  list_test(l, list_push_front, list_pop_back, 786723, 0.12078);
  list_test(l, list_push_back, list_pop_front, 96753, 1.008962);
  list_test(l, list_push_back, list_pop_back, 2344, 0.12046);

  srand(time(0));
  for (i = 0; i < 5; ++i) {
    d = (double*)malloc(sizeof(*d));
    *d = rand() % 24435 * 0.00431;
    list_push_back(l, d);
  }
  list_circular(l, 5);
  while (!list_empty(l)) {
    d = list_pop_back(l);
    free(d);
  }

  list_delete(&l);

  return 0;
}
示例#7
0
文件: list.c 项目: yoones/hsn
void		list_pop_node(t_list *list, t_lnode *node)
{
  t_lnode	*w;

  if (list->size < 3)
    {
      if (list->head == node)
	list_pop_front(list);
      else if (list->tail == node)
	list_pop_back(list);
    }
  else
    {
      for (w = list->head; w != NULL; w = w->next)
	{
	  if (w == node)
	    {
	      node->prev->next = node->next;
	      node->next->prev = node->prev;
	      list->size--;
	      free(node);
	      return ;
	    }
	}
    }
}
示例#8
0
文件: list.c 项目: Drooids/Corange
void list_clear_with(list* l, void func(void*)) {
  
  while( l->num_items > 0) {
    void* item = list_pop_back(l);
    func(item);
  }
  
}
示例#9
0
void text_free(text_t * self) {
    int count = list_getCount(self->event_notification);
    for (int i = 0; i < count; i++) {
        event_t * ev = list_pop_back(self->event_notification);
        free(ev);
    }
    list_free(self->event_notification);
    free(self);
}
示例#10
0
文件: list.c 项目: Drooids/Corange
void list_delete_with(list* l, void func(void*)) {
  
  while( l->num_items > 0) {
    void* item = list_pop_back(l);
    func(item);
  }
  
  free(l->items);
  free(l);
}
示例#11
0
void
webpage_free(webpage_t * self) {
    int count = list_getCount(self->event_notification);
    for (int i = 0; i < count; i++) {
        event_t * ev = list_pop_back(self->event_notification);
        free(ev);
    }
    list_free(self->event_notification);
    free(self->event_linkclick);
    free(self);
}
示例#12
0
//deleting event from list, checking value
static void pop_EventFromList_Event (void ** state)
{
    list_t * list = list_new();
    event_t * ev = malloc(sizeof(event_t));
    ev->receiver = NULL;
    ev->callback = NULL;
    list_push_back(list, ev);
    assert_memory_equal(list_pop_back(list), ev, 0);
    free(ev);
    free(list);
}
示例#13
0
/**
 * Delete the element at the begin of stack.
 */
void stack_pop(cstl_stack_t* psk_stack)
{
    assert(psk_stack != NULL);

#if defined (CSTL_STACK_VECTOR_SEQUENCE)
    vector_pop_back(&psk_stack->_t_sequence);
#elif defined (CSTL_STACK_LIST_SEQUENCE)
    list_pop_back(&psk_stack->_t_sequence);
#else
    deque_pop_back(&psk_stack->_t_sequence);
#endif
}
示例#14
0
int	list_clear(t_list *list, void (*freedata)(void*))
{
  int	res;

  if (list == NULL)
  {
    errno = EINVAL;
    return (-1);
  }
  while (list->nb_elm > 0)
    if ((res = list_pop_back(list, freedata)) != 0)
      return (res);
  return (0);
}
示例#15
0
void pop(char *args, List *list, Node **current, int pd)
{
	int n;
	if (pd == pd_front)
	{
		if (*current == list->first)
			*current = NULL;
		if (list_pop_front(list, &n))
			printf("%d\n", n);
	}
	else
	{
		if (*current == list->last)
			*current = NULL;
		if (list_pop_back(list, &n))
			printf("%d\n", n);
	}
}
void		list_remove_at(t_list *list, int index)
{
  if (list && list->size != 0 &&
      index < list->size && index >= 0)
    {
      if (index == (list->size - 1))
	list_pop_back(list);
      else if (index == 0)
	list_pop_front(list);
      else
	{
	  if (index < (list->size / 2))
	    pop_from_front(list, index);
	  else
	    pop_from_tail(list, index);
	}
    }
}
示例#17
0
void changeSitFile(file_t * fil, folder_t * new_fold){
    list_push_back(new_fold, fil);
    list_pop_back(fil);
}
示例#18
0
void list_clear(list_t * self) {
    while (self->size > 0) {
        void * val = list_pop_back(self);
        _dealloc(self, val);
    }
}
示例#19
0
文件: queue.c 项目: kevwan/libcstl
void queue_pop(queue q)
{
    list_pop_back(q->list_);
}
示例#20
0
文件: dlist.c 项目: vishesh/ecs352
int main()
{
    List *l = list_new();
    char choice = '\0';
    int pos, data;

    while (choice!='x') {
        printf("\nLinked List\n--------------------------------");
        printf("\n\n\nWhat would you like to do?\n");
        printf("\n  1. Insert at First Position");
        printf("\n  2. Insert at Last Position");
        printf("\n  3. Insert at nth Position");
        printf("\n  4. Delete First Element");
        printf("\n  5. Delete Last Element");
        printf("\n  6. Delete from nth Position");
        printf("\n  7. Print the List");
        printf("\n  x. Exit");
        printf("\n\nEnter Choice: ");
        fflush(stdin);
        scanf("%c", &choice);
        printf("-----\n");
        switch (choice) {
        case 'x':
            break;
        case '1':
            printf("\nEnter data: ");
            scanf("%d", &data);
            list_push_front(l, data);
            print_list(l);
            break;
        case '2':
            printf("\nEnter data: ");
            scanf("%d", &data);
            list_push_back(l, data);
            print_list(l);
            break;
        case '3':
            printf("\nEnter data: ");
            scanf("%d", &data);
            printf("Enter position: ");
            scanf("%d", &pos);
            list_insert_at(l, pos, data);
            print_list(l);
            break;
        case '4':
            list_pop_front(l);
            print_list(l);
            break;
        case '5':
            list_pop_back(l);
            print_list(l);
            break;
        case '6':
            printf("Enter position: ");
            scanf("%d", &pos);
            list_delete_at(l, pos);
            print_list(l);
            break;
        case '7':
            print_list(l);
            break;
        }

    }
    list_free(l);
}