Ejemplo n.º 1
0
int
main(int argc, char *argv[])
{

#ifndef _LIST_
/*双链表实现*/
	dlist dl;
	dl = init_dlist(dl);
	rand_dlist(dl, SIZE, MAX_NUM);
	printf("this is doubly list.\n");
	print_dlist(dl);
	exchange_dlnode(dl->next->next, dl);
	print_dlist(dl);
#else
/*单链表实现*/
	list l;
	l = init_list(l);
	rand_list(l, SIZE, MAX_NUM);
	printf("this is single list.\n");
	print_list(l);
	exchange_lnode(l->next->next, l);
	print_list(l);
#endif
	return 0;

}
Ejemplo n.º 2
0
Archivo: minmem.c Proyecto: up2u/drv
/*-----------------------------init_hash_tab()---------------------------------
* Function: init_hash_tab() 
* Purpose: init hash table 
*         
* Parameters:
*		tab (IN) -- address of table
*       size (IN) -- table size  
* Return: void
*-----------------------------------------------------------------------------*/
void init_hash_tab(struct gdlist *tab, int size)
{
	int i=0;
	for(i=0; i<size; i++){
		init_dlist(&tab[i]);
	}
}
Ejemplo n.º 3
0
//1.初始化
Queue *init_queue(void)
{
    Queue *queue = (Queue *)Malloc(sizeof(Queue));
    queue->dlist = init_dlist();

    return queue;
}
Ejemplo n.º 4
0
Stack *init_stack(void)
{
    Stack *stack = NULL;
    stack = (Stack *)Malloc(sizeof(Stack));
    stack->dlist = init_dlist();
    printf("%x\n", stack->dlist);
    return stack;
}
Ejemplo n.º 5
0
int
main (int   argc,
      char *argv[])
{
  dnode *t;
  init_dlist ();

  ordered_insert (10);
  ordered_insert (5);
  ordered_insert (8);
  ordered_insert (3);
  ordered_insert (1);
  ordered_insert (7);
  ordered_insert (8);

  printf ("\nInitial Linked list is ");
  print_dlist (head->next);

  printf ("\nFinding 4 is %ssuccessful", find_dnode (4) == tail ? "un" : "");

  t = find_dnode (5);
  printf ("\nFinding 5 is %ssuccessful", t == tail ? "un" : "");

  printf ("\nInserting 7 before 5");
  insert_dnode_ptr (7, t);
  print_dlist (head->next);

  t = find_dnode (3);
  printf ("\nDeleting 3 ");
  delete_dnode_ptr (t);
  print_dlist (head->next);

  printf ("\nInserting node 2 before 10");
  insert_dnode (2, 10);
  print_dlist (head->next);

  printf ("\nDeleting node 2");
  if (!delete_dnode (2))
    printf ("\n deleting 2 is unsuccessful");
  print_dlist (head->next);

  printf ("\nDeleting node 1");
  delete_dnode (1);
  print_dlist (head->next);

  printf ("\nInserting 15 at first");
  insert_dnode_ptr (15, head->next);
  print_dlist (head->next);

  printf ("\nDeleting all node");
  delete_all ();

  print_dlist(head->next);

  return 0;
}
Ejemplo n.º 6
0
int main(int argc, char **argv)
{
    Dlist *dlist = NULL;

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

    
   
    destroy_dlist(&dlist);    //双端链表的销毁
    return 0;
}
Ejemplo n.º 7
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;
}
Ejemplo n.º 8
0
void dlist_create(dlist_t *l)
{
    if (dlist_node_salloc_id == -1) {
        init_dlist();
    }
    
    l->count = 0;
    l->head = NULL;
    l->tail = NULL;
    
    kthread_mutex_init(&l->lock);
}
Ejemplo n.º 9
0
dlist_t *dlist_new()
{
    dlist_t *l = NULL;
    
    if (dlist_salloc_id == -1) {
        init_dlist();
    }
    
    l = salloc(dlist_salloc_id);
    dlist_create(l);
    
    return l;
}
Ejemplo n.º 10
0
Archivo: main.c Proyecto: dixe/osm-G1
int main(){

  char * a = "a";
  char * b = "b";
  char * d = "d";
  char * c ;



  dlist* list = (dlist*)init_dlist();

  insert(list, a, 0); // insert 'a' at head
  insert(list,b,0);
  c = extract(list,1);
  printf("c is: %s\n",c); // should print "a"

  c = extract(list,1);  //should be empty now
  printf("c is: %s\n",c); // should print "b"

  insert(list, b, 0); // insert 'b' at head

  printf("c is: %s\n",c); // should print "b"
  c = extract(list,0);  //should be empty now

  printf("we insert 3 new b,d,a\n");

  insert(list, b, 0); // insert 'b' at head
  insert(list, d, 0); // insert 'd' at head
  insert(list, a, 0); // insert 'a' at head

  reverse(list);

  int test = ( (int) search(list,match_a));
  if(test ){
    printf("We found a 'a'\n");
  }

  c = extract(list,0);
  printf("c is: %s\n",c); // should print "b"
  c = extract(list,0);
  printf("c is: %s\n",c); // should print "d"
  c = extract(list,0);
  printf("c is: %s\n",c); // should print "a"

  return 0;
}
Ejemplo n.º 11
0
int
dcc_dir(CELL * c)
{
    CELL compile = {0};
    int i;

    compile.window = c->window;
    compile.keytable = file_cpy_menu;
    compile.func_table = compile_cpy_table;
    compile.ListEntryProc = File_Entry;
    compile.UpdateStatusProc = status_update;
    compile.redraw = TRUE;
    compile.ListExitProc = dcc_Exit;
    compile.ListPaintProc = credraw;

    compile.srow = 3;
    compile.scol = 1;
    compile.erow = compile.window->_maxy - 5;
    compile.ecol = compile.window->_maxx - 1;
    compile.max_rows = compile.window->_maxy;
    compile.max_cols = compile.window->_maxx;

    compile.filename = "[ BitchX DCC Config ]";
    compile.menu_bar = 0;
    compile.normcolor = 0x07;
    compile.barcolor = 0x1f;
    init_dlist(&compile);
    for (i = 0; dcc_default[i].option; i++)
        insert_fdlist(&compile, &dcc_default[i]);


    /*
    * Go Do It
    */
    do {
        compile.redraw = TRUE;
        ls_dispatch(&compile);
    } while (compile.termkey != ESC && compile.termkey != ALT_X);

    c->redraw = TRUE;
    return TRUE;
}
Ejemplo n.º 12
0
/*
 * In this case also setup the old drive and path information, set the
 * current path to Quote Master export directory and filename to worksheet
 * extension
 */
int
main_dir(CELL * c)
{
    int i;

    getcwd(current_path, sizeof(current_path));
    strcat(current_path, "/.config.h");
    load_file(current_path);

    c->keytable = file_cpy_menu;
    c->func_table = file_cpy_table;
    c->ListEntryProc = File_Entry;
    c->UpdateStatusProc = status_update;
    c->redraw = TRUE;
    c->ListExitProc = List_Exit;
    c->ListPaintProc = fredraw;

    c->srow = 3;
    c->scol = 1;
    c->erow = c->window->_maxy - 5;
    c->ecol = c->window->_maxx - 1;
    c->max_rows = c->window->_maxy;
    c->max_cols = c->window->_maxx;

    c->filename = "[ BitchX Config ]";
    c->menu_bar = 0;
    c->normcolor = 0x07;
    c->barcolor = 0x1f;
    init_dlist(c);
    for (i = 0; config_type[i].option; i++)
        insert_fdlist(c, &config_type[i]);


    /*
    * Go Do It
    */
    do {
        c->redraw = TRUE;
        ls_dispatch(c);
    } while (c->termkey != ESC && c->termkey != ALT_X);
    return TRUE;
}
Ejemplo n.º 13
0
//hash表插入元素
Boolean hash_insert(Hash *hash, const void *value)
{
    //如果hash表不存在或元素已经存在于桶中,则不进行插入
    if(NULL == hash || NULL == value || TRUE == hash_search(hash, value))
    {
        return FALSE;
    }
    int i = 0;
    int bucket = 0;
    //判断元素所在桶的下标
    bucket = hash->hash_func(value) % hash->bucket_size;
    //插入操作时,如果桶不存在,则初始化这个桶
    if(NULL== hash->table[bucket] )
    {
        hash->table[bucket] = init_dlist();
    }
    //通过尾插将元素插入当前桶
    push_back(hash->table[bucket], (void *)value);
    hash->element_count ++;
    return TRUE;
}
Ejemplo n.º 14
0
Archivo: list.c Proyecto: e7/analysis
int main(int argc, char *argv[])
{
#if 0
    intptr_t list = 0;
    data_t data[8];
    int i = 0;
    intptr_t iter = 0;

    for (i = 0; i < ARRAY_COUNT(data); ++i) {
        data[i].__x__ = i;
        list_add(&list, &data[i].__node__);
    }

    assert(0 == list_rm(&list, 0));
    assert(0 == list_rm(&list, 7));

    iter = list;
    while (0 != iter) {
        data_t *data = CONTAINER_OF((intptr_t *)iter, data_t, __node__);

        (void)fprintf(stderr, "%d\n", data->__x__);
        iter = *(intptr_t *)iter;
    }

    return 0;
#endif

#if 0
    intptr_t head = 0;
    intptr_t node = 0;

    (void)fprintf(stderr, "&head: %p, &node: %p\n", &head, &node);
    list_add(&head, &node);
    (void)fprintf(stderr, "head: %x, node: %x\n", head, node);
    list_remove(&head);
    (void)fprintf(stderr, "head: %x, node: %x\n", head, node);

    return 0;
#endif

#if 0
    intptr_t i = 0;
    data_t data[8];

    print_data((data_t){9, 0, {0, 0}});
    memset(data, 0, SIZE_OF(data));
    arraylist_add(&data[0].__node__, &data[2].__node__, 2);
    arraylist_add(&data[2].__node__, &data[3].__node__, 3);
    arraylist_add(&data[3].__node__, &data[7].__node__, 7);
    arraylist_del(&data[0].__node__, &data[2].__node__);
    for (i = 0; i < (intptr_t)ARRAY_COUNT(data); ++i) {
        (void)fprintf(stderr, "data[%d] : %d\n", i, data[i].__node__);
    }

    memset(data, 0, SIZE_OF(data));
    arraydlist_add(&data[0].__dnode__,
                   &data[0].__dnode__,
                   &data[0].__dnode__,
                   0);
    arraydlist_add(&data[0].__dnode__,
                   &data[0].__dnode__,
                   &data[2].__dnode__,
                   2);
    arraydlist_add(&data[0].__dnode__,
                   &data[2].__dnode__,
                   &data[3].__dnode__,
                   3);
    arraydlist_add(&data[3].__dnode__,
                   &data[2].__dnode__,
                   &data[7].__dnode__,
                   7);
    /* that's NOT right, broke the dlist
    arraydlist_add(&data[2].__dnode__,
                   &data[3].__dnode__,
                   &data[7].__dnode__,
                   7);*/

    /*arraydlist_del(&data[3].__dnode__,
                   &data[2].__dnode__,
                   &data[7].__dnode__);*/

    for (i = 0; i < (intptr_t)ARRAY_COUNT(data); ++i) {
        (void)fprintf(stderr,
                      "data[%d] : (%d, %d)\n",
                      i,
                      data[i].__dnode__.__prev__,
                      data[i].__dnode__.__next__);
    }

    return 0;
#endif

#if 1
    typedef struct {
        intptr_t a;
        intptr_t b;
    } mydata_t;

    dlist_t dlist;
    mydata_t x1 = {1, 2};
    mydata_t x2 = {3, 4};
    mydata_t x3 = {5, 6};

    (void)init_dlist(&dlist, SIZE_OF(mydata_t));
    dlist_insert(&dlist, &x2);
    dlist_insert(&dlist, &x3);
    dlist_insert(&dlist, &x1);
    for (intptr_t iter = dlist.__head__->__next__;
         iter != 0;
         iter = dlist_next(&dlist, iter))
    {
        // mydata_t *d = CONTAINER_OF(iter, mydata_t, __dnode__);
        intptr_t shell_size = dlist.__obj_size__ + SIZE_OF(arraydlist_t);

        mydata_t *d = (mydata_t *)(dlist.__cache__ + shell_size * iter);

        fprintf(stderr, "%d, %d\n", d->a, d->b);
    }
    exit_dlist(&dlist);

    return 0;
#endif
}