Exemplo n.º 1
0
int main(int argc, char* argv[]){
  if(argc==2)
    {
      struct bag* b = (struct bag*)malloc(sizeof(struct bag));/*Create new bag*/
      initBag(b);/*Initialize*/
      char* s=argv[1];
      int n = atoi(s);/*number of elements to add*/
      int i;
      for( i = 1; i < n; ++i)
    {
	    addFrontList(b->l, (TYPE)(i));/*Add elements*/
    }
        addToBag(b, (TYPE)9);
        addToBag(b, (TYPE)3);
        addToBag(b, (TYPE)9);
     double t1 = getMilliseconds();/*Time before contains()*/
      printf("Found? %d\n", bagContains(b, (TYPE)20));
      double t2 = getMilliseconds();/*Time after contains()*/
        printf("Size: %d\n", b->l->size);
        removeFromBag(b, (TYPE)9);
        printf("Size: %d\n", b->l->size);
        addFrontList(b->l, 10.0);
        printf("Front: %f\n", frontList(b->l));
      printf("%d %g\n", n, t2-t1);
        freeBag(b);
    }
  else
  {
      printf("Please enter the number of elements to add.\n");
                }

  return 0;

}
Exemplo n.º 2
0
Arquivo: main.c Projeto: Mankee/CS261
int main(){

	struct bag* b = (struct bag*)malloc(sizeof(struct bag));/*Create new bag*/
	initBag(b);/*Initialize*/

    printf("size of list = %d \n", b->lst->size);
    printf("\n");

    addFrontList(b->lst, 3);
    addFrontList(b->lst, 2);
    addBackList(b->lst, 4);
    addBackList(b->lst, 5);
    addBackList(b->lst, 6);
    addFrontList(b->lst, 1);

    int i;
    struct DLink *currentlink = b->lst->head->next;
    for(i = 1; i <= b->lst->size; i++){
            printf("index %d = %d \n", i, currentlink->value);
            currentlink = currentlink->next;
    }
    printf("\n");
    printf("front = %d \n", frontList(b->lst));
    printf("back = %d \n", backList(b->lst));
    printf("is list empty? = %d \n", isEmptyList(b->lst));
    printf("size of list = %d \n", b->lst->size);
    printf("list contains = %d \n", listContains(b->lst, 12));

    printf("\n");
    addToBag(b, 10);
    removeFromBag(b, 1);
    struct DLink *link = b->lst->head->next;
    for(i = 1; i <= b->lst->size; i++){
            printf("index %d = %d \n", i, link->value);
            link = link->next;
    }
    printf("list contains = %d \n", bagContains(b, 100));

    return 0;

}