コード例 #1
0
ファイル: Stack.c プロジェクト: rajiv256/CodingIsFun
Stack* stack_push(Stack* st,int val)
{

    st->list=llist_prepend(st->list,val);
    return (st);

}
コード例 #2
0
ファイル: util_streambuf.c プロジェクト: gwtony/wsocket
int streambuf_unread(streambuf_t *p, struct streambuf_iov_st *iov)
{
	struct streambuf_st *buf=p;

	pthread_mutex_lock(&buf->mut);
	pthread_cleanup_push(mutex_unlock, &buf->mut);
	llist_prepend(buf->ringbuf, iov);
	buf->nr_bytes += iov->len;
	pthread_cond_signal(&buf->cond);
	pthread_cleanup_pop(1);
	return 0;
}
コード例 #3
0
ファイル: parse.c プロジェクト: SrTobi/fakeasm
void push_function(const char* name, VarList params)
{
    Function* context = NULL;
    if(funstack != llist_empty)
    {
        context = llist_head(funstack);
    }
    
    Function* f = new_function(name, context);
    
    add_all_params(params, f);
    
    funstack = llist_prepend(f, funstack);
}
コード例 #4
0
ファイル: Stack.c プロジェクト: rajiv256/CodingIsFun
void stack_print(Stack* st)
{
    LList* new3=(LList*)malloc(sizeof(LList));
    new3->head=(Node*)malloc(sizeof(Node));
    LList* new2=(LList*)malloc(sizeof(LList));
    new2->head=(Node*)malloc(sizeof(Node));
    new3=llist_new();
    new2->head=st->list->head;
    while (new2->head!=NULL)
    {
        new3=llist_prepend(new3,new2->head->data);
        new2->head=new2->head->next;
    }
    llist_print(new3);
}
コード例 #5
0
LList* llist_insert( LList* lst, int idx, int data )
{
    Node* ptr;
    ptr = lst->head;
    int i;
    if(idx==0) return llist_prepend(lst, data);
    else
    {
		for(i=0;i<idx-2;i++)
		{
			ptr = ptr->next;
		}
		if(idx>=2) ptr = ptr->next;
		ptr->next = node_new(data, ptr->next); 
	}  
    return lst;   
}
コード例 #6
0
ファイル: parse.c プロジェクト: SrTobi/fakeasm
void push_label(const char* name)
{
    Function* curf = cur_func();
    
    // check if label already exists
    Label** foundl = strmap_find(curf->labels, name);
    if(foundl != NULL)
        yyerrerf("A label with the name '%s' has already been defined in function '%s'.", name, curf->name);
    
    /*llist_foreach(LabelList, curf->labels, l)
    {
        if(strcmp(l->name, name) == 0)
        {
            
        }
    }*/    
    
    Label* l = new_label(name);
    curlabels = llist_prepend(l, curlabels);
    
    strmap_insert(curf->labels, name, l);
    //curf->labels = llist_prepend(l, curf->labels);
}
コード例 #7
0
ファイル: ds_llist.c プロジェクト: gwtony/wsocket
void func_test()
{
	char *s = "this is a test";
	char *s2 = "x";
	void *b;
	int i, j;
	llist_t *ll;

	/*
	 * test 1
	 */

	ll = llist_new(20);	
	for (i = 0; i < 4; i++) {
		if (i%3 == 0) {
			llist_append(ll, &s2[0]);
		}
		llist_append(ll, &s[i]);
	}
	
	llist_travel(ll, &show);
	printf("\n");
	for (i = 0; i < 4; i++) {
		llist_prepend(ll, &s[0]);
	}
	llist_travel(ll, &show);
	printf("\n");
	for (i = 0; i < 4; i++) {
		llist_prepend_nb(ll, &s[1]);
	}
	llist_travel(ll, &show);
	printf("\n");
	llist_fetch_head(ll, &b);
	llist_travel(ll, &show);
	printf("\n");
	llist_fetch_head(ll, &b);
	llist_travel(ll, &show);
	printf("\n");
	llist_delete(ll);
	
	printf("%stest1 successful%s\n", COR_BEGIN, COR_END);

	/*
	 * test 2
	 */

	ll = llist_new(1000);
	for (j = 0; j < 100; j++) {
		for (i = 0; i < 10; i++) {
			llist_append_nb(ll, &s[i]);
		}
	}
	printf("append done.\n");
	for (i = 0; i< 100; i++) {
		llist_fetch_head_nb(ll, &b);
		printf("%c", *(char *)b);
	}
	printf("\nthere are %d nodes\n", ll->nr_nodes);
	for (i = 0; i< 100; i++) {
		llist_get_head_nb(ll, &b);
		printf("%c", *(char *)b);
	}
	printf("\n");
	printf("%stest2 successful%s\n", COR_BEGIN, COR_END);
	printf("there are %d nodes\n", ll->nr_nodes);
	
	/*
	 * test 3
	 */
	void *ptr, *ptr2;
	llist_get_head_node_nb(ll, &ptr);
	for (i = 0; i< 100; i++) {
		printf("%c", *(char *)(((llist_node_t *)ptr)->ptr));
		ptr = llist_get_next_nb(ll, ptr);
	}
	printf("\nthere are %d nodes\n", ll->nr_nodes);
	llist_delete(ll);
	printf("%stest3 successful%s\n", COR_BEGIN, COR_END);
	return;
}
コード例 #8
0
int play_TOH(LList* lst_1, LList* lst_2 ,LList* lst_3){
    int num_steps=0;
    int lst_1_size,lst_2_size;
    int k=llist_size(lst_1);
    int p=llist_size(lst_3);
    printf("\nTransfer\tpeg1\tpeg2\tpeg3\n");
    if(k%2!=0){
    while(p!=k)
    {
       switch(num_steps%3)
       {
       
      case 0:
             if(lst_3->head==NULL || lst_1->head->data < lst_3->head->data)
             {
                 lst_3=llist_prepend(lst_3,lst_1->head->data);
                 lst_1=llist_remove_first(lst_1);
                 printf("1 -> 3");
             }
             else 
              {
                 lst_1=llist_prepend(lst_1,lst_3->head->data);
                 lst_3=llist_remove_first(lst_3);
                 printf("3 -> 1");
             }
             num_steps++;
             break;
             
     case 1:
           if(lst_2->head==NULL || lst_1->head->data < lst_2->head->data)
             {
                 lst_2=llist_prepend(lst_2,lst_1->head->data);
                 lst_1=llist_remove_first(lst_1);
                 printf("1 -> 2");
             }else{
             if(lst_1->head->data==1000)
             lst_1=llist_remove_first(lst_1);
                lst_1=llist_prepend(lst_1,lst_2->head->data);
                 lst_2=llist_remove_first(lst_2);
                 printf("2 -> 1");
             }
             num_steps++;
             break;
     
     case 2:
           if(lst_3->head==NULL || lst_2->head->data < lst_3->head->data)
             {
                 lst_3=llist_prepend(lst_3,lst_2->head->data);
                 lst_2=llist_remove_first(lst_2);
                 printf("2 -> 3");
             }
             else 
              {
                 lst_2=llist_prepend(lst_2,lst_3->head->data);
                 lst_3=llist_remove_first(lst_3);
                 printf("3 -> 2");
             }
             num_steps++;
             break;
          default :
              break;
       }
       if(lst_1->head==NULL)
       lst_1=llist_prepend(lst_1,1000);
       p=llist_size(lst_3);
       lst_1_size=llist_size(lst_1);
       lst_2_size=llist_size(lst_2);
      if(lst_1->head->data==1000)
       lst_1_size-=1;
       printf("\t\t %d\t%d\t%d\n",lst_1_size,lst_2_size,p);
    }
}else{
      while(p!=k)
      {
       switch(num_steps%3)
       {
       case 0:
             if(lst_2->head==NULL || lst_1->head->data < lst_2->head->data)
             {
                 lst_2=llist_prepend(lst_2,lst_1->head->data);
                 lst_1=llist_remove_first(lst_1);
                 printf("1 -> 2");
             }
             else
              {
               if(lst_1->head->data==1000)
               lst_1=llist_remove_first(lst_1);
                 lst_1=llist_prepend(lst_1,lst_2->head->data);
                 lst_2=llist_remove_first(lst_2);
                 printf("2 -> 1");
             }
             num_steps++;
             break;
             
     case 1:
           if(lst_3->head==NULL || lst_1->head->data < lst_3->head->data)
             {
                 lst_3=llist_prepend(lst_3,lst_1->head->data);
                 lst_1=llist_remove_first(lst_1);
                 printf("1 -> 3");
             }
             else
              {
                 lst_1=llist_prepend(lst_1,lst_3->head->data);
                 lst_3=llist_remove_first(lst_3);
                 printf("3 -> 1");
             }
             num_steps++;
             break;
     
     case 2:
           if(lst_3->head==NULL || lst_2->head->data < lst_3->head->data)
             {
                 lst_3=llist_prepend(lst_3,lst_2->head->data);
                 lst_2=llist_remove_first(lst_2);
                 printf("2 -> 3");
             }
             else
              {
                 lst_2=llist_prepend(lst_2,lst_3->head->data);
                 lst_3=llist_remove_first(lst_3);
                 printf("3 -> 2");
             }
             num_steps++;
             break;
        default:
             break;  
       }
        if(lst_1->head==NULL)
       lst_1=llist_prepend(lst_1,1000);
       p=llist_size(lst_3);
       lst_1_size=llist_size(lst_1);
       lst_2_size=llist_size(lst_2);
       if(lst_1->head->data==1000)
       lst_1_size=-1;
       printf("\t\t %d\t%d\t%d\n",lst_1_size,lst_2_size,p);
       
     }
  }
  return num_steps;
}