Beispiel #1
0
static int test03 ( void ) {
  list_t *p = NULL;

  printf("\ntest03 - test list_add_front\n" );

  p = list_create();
  printf("test03 - test list_add-front as first element\n");
  list_add_front (p, 666);
  list_show(p);

  printf("test03 - test list_add-front element\n");  
  list_add ( p, 101);
  list_add ( p, 201);
  list_add ( p, 301);
  list_add ( p, 401);
  list_show(p);
  list_add_front (p, 999);
  list_show(p);
  list_add_front (p, 888);
  list_show(p);
  list_add_front (p, 777);
  list_show(p);
  
  return 0;
}
Beispiel #2
0
static void tcase_add_fixture (TCase *tc, SFun setup, SFun teardown,
			       int ischecked)
{
  if (setup) {
    if (ischecked)
      list_add_end (tc->ch_sflst, fixture_create(setup, ischecked));
    else
      list_add_end (tc->unch_sflst, fixture_create(setup, ischecked));
  }

  /* Add teardowns at front so they are run in reverse order. */
  if (teardown) {
    if (ischecked)
      list_add_front (tc->ch_tflst, fixture_create(teardown, ischecked));
    else
      list_add_front (tc->unch_tflst, fixture_create(teardown, ischecked));  
  }
}
Beispiel #3
0
END_TEST


START_TEST(test_add_front_and_next)
{
  List * lp = check_list_create();
  const char *tval1 = "abc";
  const char *tval2 = "123";
  
  list_add_front (lp, tval1);
  list_add_front (lp, tval2);
  list_front(lp);
  fail_unless (strcmp (tval2, list_val (lp)) == 0,
	       "List head val should equal last inserted val");
  list_advance (lp);
  fail_unless (!list_at_end (lp),
	       "List should not be at end after two adds and one next");
  fail_unless (strcmp (tval1, list_val (lp)) == 0,
	       "List val should equal first inserted val");
  list_advance(lp);
  fail_unless (list_at_end (lp),
	       "List should be at and after two adds and two nexts");
  list_free (lp);
}
Beispiel #4
0
END_TEST

START_TEST(test_add_front)
{
  List * lp = check_list_create();
  const char * tval = "abc";
  
  list_add_front (lp, tval);
  
  fail_unless (list_val (lp) != NULL,
	       "List current val should not be null after new insertion");
  fail_unless (strcmp(tval, (char *) list_val (lp)) == 0,
	       "List current val should equal newly inserted val");
  list_free (lp);
}
Beispiel #5
0
END_TEST

START_TEST(test_add_a_bunch)
{
  List *lp;
  int i, j;
  for (i = 0; i < 3; i++) {
    lp = check_list_create();
    for (j = 0; j < 1000; j++) {
      list_add_end (lp, "abc");
      list_add_front (lp, "123");
    }
    list_free(lp);
  }
}
Beispiel #6
0
static int32_t cmdqueue_wait_cmd(cmdqueue_t handle, struct cmd *cmd)
{

    PTHREAD_CHK(pthread_mutex_lock(&handle->queues[CMDDONE].mutex));

    while (!cmd_finished(&handle->queues[CMDDONE].head, cmd) ) {
        PTHREAD_CHK(pthread_cond_wait(&handle->queues[CMDDONE].cond,
                    &handle->queues[CMDDONE].mutex));
    }

    list_remove(&cmd->head);

    PTHREAD_CHK(pthread_mutex_unlock(&handle->queues[CMDDONE].mutex));

    PTHREAD_CHK(pthread_mutex_lock(&handle->queues[CMDFREE].mutex));
    list_add_front(&handle->queues[CMDFREE].head, &cmd->head);
    PTHREAD_CHK(pthread_cond_broadcast(&handle->queues[CMDFREE].cond));
    PTHREAD_CHK(pthread_mutex_unlock(&handle->queues[CMDFREE].mutex));

    // always returns 0, make void?
    return 0;
}
 main()
 {
     nodeptr one=NULL;
     nodeptr two=NULL;
     nodeptr ans=NULL;
     one=malloc(sizeof(nodeptr));
     two=malloc(sizeof(nodeptr));
     ans=malloc(sizeof(nodeptr));
     initialize(one,two,ans);
     char a[10000];
     printf("first number =");
     scanf("%s",a);
     int l1=num_list_add_leng(one,a);
  
     fflush(stdin);
     printf("\n second number =");
     scanf("%s",a);
     int l2=num_list_add_leng(two,a);
     list_print(one->next);
     printf("\n");
     list_print(two->next);
     printf("\n  */+/-  ? = ");
     char pr;
     scanf(" %c",&pr);
     printf("\n");
     int i=0,j=0,buffer=0;
     nodeptr add[l2];
     int flow=1;
  if((pr=='+')&&flow){
      addit(one,two,ans);
      list_print(ans->next);
      flow=0;
  }
  if((pr=='-')&&flow)
  {
  
      subtract(one,two,ans);
      stripLeadingZeros(ans->next);
      list_print(ans->next);
      flow=0;
  }
  if((pr=='/')&&flow)
  {
      divide(one,two,ans);
      list_print(ans->next);
      flow=0;
  }
  if((pr=='*')&&flow){                                         //note: ans node is useless for addition from here used as temp mem frm here
 for(j=0;j<l2;j++)
 {
     add[j]=malloc(sizeof(nodeptr));
     add[j]->next=NULL;
     int ts=j;
     while(ts!=0)
     {
        list_add_front(add[j],0);
        ts--;
     }
      ans=one;
     int tmp1=two->next->data;
  for(i=0;i<l1;i++){
       int tmp=one->next->data;
       int tmp3=(tmp1*tmp)+buffer;
       list_add_front(add[j],(tmp3)%10);
       buffer=(tmp3)>9?(tmp3/10):0;
           one=one->next;
                   }
                   one=ans;
 if(buffer>=1){
 list_add_front(add[j],buffer);
  
 }
 two=two->next;
 buffer=0;
 }
 i=0;
 freemem(ans);
 nodeptr ans1;
 ans1=malloc(sizeof(nodeptr));
 ans1->next=NULL;
 j=l2;
 while(j>=2){
   addit(add[i],add[i+1],ans1);
   add[i+1]=ans1;
   i++;
   j--;
 }
  
  
 printf("\n");
 list_print(add[l2-1]->next);
 }
 printf("\n written by Namit Sinha");
 getch();
 }