Exemple #1
0
int	loop_main(t_sh *sh, pid_t pid)
{
    if (sh == NULL)
        return (EXIT_FAILURE);
    while (is_open(NULL))
    {
        my_printf("%s", sh->rdl.prompt);
        if ((get_readline(sh)) == false)
            return (unload_sh(sh));
        sh->tok_list = tokenizer((char*)sh->line, sh->env);
        sh->line = gbgc_free(NULL, sh->line);
        parser(sh);
        my_main(sh, sh->env);
        if (!is_open(NULL))
        {
            if (pid == getpid())
            {
                dezombificator2(0);
                unload_sh(sh);
            }
            return (get_exitstate(NULL));
        }
        sh->prs_list = destroy_dlist(sh->prs_list, free_t_prs);
    }
    if ((unload_sh(sh)) == FALSE)
        return (EXIT_FAILURE);
    return (get_exitstate(NULL));
}
Exemple #2
0
void destroy_dlist(dlist *l)
{
   if (NULL != l)
   {
     destroy_dlist(l->next);
     destroy_dlist_node(l);
   }
}
Exemple #3
0
//2.销毁
void destroy_queue(Queue **queue)
{
    if(queue == NULL || *queue == NULL)
    {
        return;
    }
    destroy_dlist( &((*queue)->dlist) );
    free(*queue);
    *queue = NULL;
}
Exemple #4
0
/*
 * Deallocate all dlist nodes
 * Destroy Stack
 */
bool destroy_stack(stack_p stack)
{
	if (destroy_dlist(stack->head) == -1)
		return FALSE;

	free(stack->head);
	free(stack);

	return TRUE;
}
Exemple #5
0
int main(int argc, char **argv)
{
    Dlist *dlist = NULL;

    dlist = init_dlist();   //双端链表的初始化

    
   
    destroy_dlist(&dlist);    //双端链表的销毁
    return 0;
}
Exemple #6
0
/*
void print_int(void *value);
void print_int(void *value)
{
    printf("%d ",*(int *)value);
 }
*/
int main(int argc, char **argv)
{
    int i = 0;
    int a[]={1,2,3,4,5};
    void *value;

    Dlist *dlist = NULL;
    dlist = init_dlist();
    printf("3.push_front(dlist, &a[i]);\n");
    for(i=0; i< sizeof(a)/sizeof(a[0]);++i)
    {
        push_front(dlist, &a[i]);
    }
    show_dlist(dlist, print_int);
    printf("5.pop_front(dlist);\n");
    pop_front(dlist);

    show_dlist(dlist, print_int);
    printf("4.push_back(dlist, &a[i]);\n");
    for(i=0; i< sizeof(a)/sizeof(a[0]);++i)
    {
        push_back(dlist, &a[i]);
    }
    show_dlist(dlist, print_int);
    printf("6.pop_back(dlist);\n");
    pop_back(dlist);
    show_dlist(dlist, print_int);
    
    printf("7.insert_prev(dlist, dlist->head->next->next, &a[4]);\n");
    insert_prev(dlist, dlist->head->next->next, &a[4]);
    show_dlist(dlist, print_int);

    printf("8.insert_next(dlist, dlist->head->next->next, &a[4]);\n");
    insert_next(dlist, dlist->head->next->next, &a[4]);
    show_dlist(dlist, print_int);

    printf("9.remove_dlist_node(dlist, dlist->head->next->next->next);\n");
    remove_dlist_node(dlist, dlist->head->next->next->next);
    show_dlist(dlist, print_int);
   
    get_front(dlist, &value);
    printf("\n11.get_front:\n");
    print_int(value);

    get_tail(dlist, &value);
    printf("\n12.get_tail:\n");
    print_int(value);

    printf("\n13.get_dlist_count:\n");
    printf("%d \n",get_dlist_count(dlist));
    destroy_dlist(&dlist);
    return 0;
}
Exemple #7
0
//2.哈希表的销毁
void    destroy_hash(Hash **hash)                      //哈希表的销毁
{
   int i = 0;
   int bucket_size = 0;
   Hash *p_hash = NULL;
   //   销毁步骤:
   //1. 销毁每一个桶(双端链表);
   //2. 销毁table;
   //3. 销毁hash;
    if(hash == NULL || *hash == NULL){
        return ;
    }
    p_hash = *hash;
    bucket_size = p_hash->bucket_size;
    for(i = 0; i < bucket_size; ++i){
        destroy_dlist(&(p_hash->table[i]));
    } 
    free(p_hash->table);
    free(p_hash);
    p_hash = NULL;
}