Пример #1
0
int lru_cache_destroy(cache_t *c)
{
    apr_status_t value;

    cache_lru_t *cp = (cache_lru_t *)c->fn.priv;

    //** Shutdown the dirty thread
    cache_lock(c);
    c->shutdown_request = 1;
    apr_thread_cond_signal(cp->dirty_trigger);
    cache_unlock(c);

    apr_thread_join(&value, cp->dirty_thread);  //** Wait for it to complete

    cache_base_destroy(c);

    free_stack(cp->stack, 0);
    free_stack(cp->waiting_stack, 0);
    free_stack(cp->pending_free_tasks, 0);

    destroy_pigeon_coop(cp->free_pending_tables);
    destroy_pigeon_coop(cp->free_page_tables);

    free(cp);
    free(c);

    return(0);
}
Пример #2
0
static gint
undo_stack_push (HexDocument *doc, HexChangeData *change_data)
{
  HexChangeData *cd;
  GList *stack_rest;

#ifdef ENABLE_DEBUG
  g_message("undo_stack_push");
#endif

  if(doc->undo_stack != doc->undo_top)
    {
      stack_rest = doc->undo_stack;
      doc->undo_stack = doc->undo_top;
      if(doc->undo_top)
        {
          doc->undo_top->prev->next = NULL;
          doc->undo_top->prev = NULL;
        }
      free_stack(stack_rest);
    }

  if((cd = g_new(HexChangeData, 1)) != NULL)
    {
      memcpy(cd, change_data, sizeof(HexChangeData));
      if(change_data->v_string)
        {
          cd->v_string = g_malloc(cd->rep_len);
          memcpy(cd->v_string, change_data->v_string, cd->rep_len);
        }

      doc->undo_depth++;

#ifdef ENABLE_DEBUG
      g_message("depth at: %d", doc->undo_depth);
#endif

      if(doc->undo_depth > doc->undo_max)
        {
          GList *last;

#ifdef ENABLE_DEBUG
          g_message("forget last undo");
#endif

          last = g_list_last(doc->undo_stack);
          doc->undo_stack = g_list_remove_link(doc->undo_stack, last);
          doc->undo_depth--;
          free_stack(last);
        }

      doc->undo_stack = g_list_prepend(doc->undo_stack, cd);
      doc->undo_top = doc->undo_stack;

      return TRUE;
    }

  return FALSE;
}
Пример #3
0
PCIPHEREXP __INTERNAL_FUNC__ ReverseCipherExpression(PCIPHEREXP pCipherExp) {
	/*
	 * 再压入操作符号与操作节点时
	 * 链中第一个节点不压入栈
	 * 最后一个操作符号不压入栈
	 *
	 * 逆向式中的第一个节点肯定没有操作符号
	 */
	__bool bIsFirst = TRUE;
	LOGIC_OPT *pOpt = NULL;
	PCIPHEREXP pReverseCipherExp = NULL, *pReverseCipherExpPoint = NULL;
	PCIPHEREXP pCurrCipherExp = pCipherExp;
	PSTACK pOptStack = init_stack(0);
	__integer i = 0, iCipherNodeCount = CountCipherNode(pCipherExp);
	PSTACK pCipherExpNodeStack = init_stack(sizeof(CIPHEREXP) * iCipherNodeCount);
	for (i = 0; i < iCipherNodeCount; i++) {
		if (i == 0) {//舍弃第一个节点
			push_stack(pOptStack, &(pCurrCipherExp->Opt), sizeof(LOGIC_OPT));
		} else if (i == iCipherNodeCount-1) {
			push_stack(pCipherExpNodeStack, pCurrCipherExp, sizeof(CIPHEREXP));
		} else {
			push_stack(pOptStack, &(pCurrCipherExp->Opt), sizeof(LOGIC_OPT));
			push_stack(pCipherExpNodeStack, pCurrCipherExp, sizeof(CIPHEREXP));
		}
		pCurrCipherExp = pCurrCipherExp->pNextExp;
	}

	/*
	 * 首先扩充第一个节点(变量)
	 */
	pReverseCipherExpPoint = &pReverseCipherExp;
	do {
		pOpt = (LOGIC_OPT *)pop_stack(pOptStack, sizeof(LOGIC_OPT));
		(*pReverseCipherExpPoint) = CreateCipherExp();

		// 如果是第一个节点
		if (bIsFirst) {
			(*pReverseCipherExpPoint)->bNot = pCipherExp->bNot;//第一个变量是否拥有NOT操作
			(*pReverseCipherExpPoint)->Opt = GenerateReverseLogicOpt(*pOpt);	
			bIsFirst = FALSE;
		} else {
			if (!pOpt)
				(*pReverseCipherExpPoint)->Opt = LOGIC_NONE;
			else
				(*pReverseCipherExpPoint)->Opt = *pOpt;
			pCurrCipherExp = (PCIPHEREXP)pop_stack(pCipherExpNodeStack, sizeof(CIPHEREXP));
			(*pReverseCipherExpPoint)->bKey = pCurrCipherExp->bKey;
			(*pReverseCipherExpPoint)->bNot = pCurrCipherExp->bNot;
			(*pReverseCipherExpPoint)->dwVal = pCurrCipherExp->dwVal;
		}/* end else */
		pReverseCipherExpPoint = &((*pReverseCipherExpPoint)->pNextExp);
	} while (pOpt);
	free_stack(pOptStack);
	free_stack(pCipherExpNodeStack);
	return pReverseCipherExp;
}
Пример #4
0
wast_iterator_t tinyap_wi_reset(wast_iterator_t wi) {
	wi->parent = NULL;
	wi->child = 0;
	if(wi->pstack) {
		free_stack(wi->pstack);
	}
	if(wi->cstack) {
		free_stack(wi->cstack);
	}
	wi->pstack = new_stack();
	wi->cstack = new_stack();
	return wi;
}
Пример #5
0
void msgc_end( msgc_context_t *context )
{
  int n;
  
  n = free_stack( context->los_stack.seg );
  n += free_stack( context->stack.seg );
  if (n > 2)
    consolemsg( "  Warning: deep mark stack: %d elements.", n*STACKSIZE );

  gclib_free( context->bitmap, context->words_in_bitmap*sizeof(word) );
  context->bitmap = 0;
  free( context );
}
Пример #6
0
/* Solve the maze
 *
 * Parameter(s): maze - maze cells
 *               w    - maze width
 *               h    - maze height
 *
 * Return: 0 on allocation error
 *         1 otherwise
 */
int solve(int **maze, const int w, const int h)
{
	struct stack *st = NULL;
	int x, y;
	int tmpx, tmpy;

	x = 1;
	y = 1;
	maze[1][0] = WALL;
	maze[h - 2][w - 1] = WALL;

	while (1) {
		/* Mark cell as part of path through the maze and save its
		 * coordinates for later adding it to the stack (for
		 * backtracking) */
		maze[y][x] = PATH;
		tmpx = x;
		tmpy = y;

		if (solve_rand_neighbour(maze, &x, &y, w, h)) {
			/* If lower right cell; we solved the maze */
			if (x == w - 2 && y == h - 2) {
				maze[y][x] = PATH;

				break;
			}
			if (!push(&st, tmpx, tmpy)) {
				free_stack(&st);

				return 0;
			}
		} else {
			/* If nowhere to go, we backtrack to the mother cell */
			maze[y][x] = UPATH;
			x = st->x;
			y = st->y;

			pop(&st);
		}
	}
	free_stack(&st);

	/* Mark exit and entrance as part of the path */
	maze[1][0] = PATH;
	maze[h - 2][w - 1] = PATH;

	return 1;
}
Пример #7
0
int main(int argc, char *argv[]) {

  stack *s = NULL;
  float arg1, arg2;
  token t;

  while(next(&t, stdin)) {
    if(t.type == T_VALUE) {
      //If this token is a value, push it on the stack.
      stack_push(&s, t.value);
    } else {
      //Otherwise, we're dealing with an operator:
      //Pop elements from the stack as necessary, and push result.
      switch(t.symbol[0]) {
        case '+': stack_push(&s, stack_pop(&s)+stack_pop(&s));
                  break;
        case '-': arg1 = stack_pop(&s);
                  arg2 = stack_pop(&s);
                  stack_push(&s, arg2-arg1);
                  break;
        case '*': stack_push(&s, stack_pop(&s)*stack_pop(&s));
                  break;
        case '/': arg1 = stack_pop(&s); 
                  arg2 = stack_pop(&s);
                  stack_push(&s, arg2/arg1);
                  break;
        case '^': arg1 = stack_pop(&s);
                  arg2 = stack_pop(&s);
                  stack_push(&s, pow(arg2, arg1));
                  break;
        case '.': printf("%g\n", stack_peek(&s));
                  break;
        case 'q': free_stack(&s);
                  printf("Exiting\n");
                  return 0;
        case 'c': free_stack(&s);
                  printf("Stack cleared.\n");
                  break;
        case 'h':
        case '?': print_usage();
                  break;
        default : printf("Unknown operator \"%s\"\n", t.symbol);
      }
    }
  }

  return 0;
}
Пример #8
0
void Kosaraju(GRAPH * G, stack * s)
{
    transfer_graph(G);
    unsigned int temp_edge;
    unsigned int i;
    if (s->top < G->size) {
	printf("Graf nie jest silnie spójny!\n");
	return;
    }
    while (stack_empty(s) != TRUE) {
	temp_edge = Pop(s);
	//printf("Pop:%d\n",temp_edge);
	if (temp_edge != 0) {
	    stack *stacks = allocation_stack(G->size, 1);
	    DFS_VISIT(G, temp_edge, stacks);
	    printf("Skladowa spojnosc: ");
	    //view_edges(G);
	    //printf("Stack top == %d\n",stacks->top);
	    while (stack_empty(stacks) != TRUE) {
		temp_edge = Pop(stacks);
		printf("%d ", temp_edge);
		delete_vertex(temp_edge, G);
		pop_false(temp_edge, s, G->size);
	    }
	   putchar('\n');


	    free_stack(stacks);

	}
    }

}
Пример #9
0
/**
  * Create a new thread, which will start to execute
  * function fp right after create() returns.
  *
  * para: fp - pointer to the function to be executed.
  *       info - not used currently
  *
  * return: 0 - create new thread successfully
  *         DWT_TID_NONE - failed to create new thread
  */
dwt_tid_t dwthread_create(int (*fp)(), void *info)
{
	/*
	 * TODO: 1. Alloc a new task_t and init its fields.
	 */
	dwt_task_t* task = malloc(sizeof(dwt_task_t));
	task->tid = generate_tid();
	task->statue = DWT_STATUE_RUNNABLE;

	/*
	 * TODO: 2. Alloc a new stack and fill in the fields
     *          in context of task_t.
     *
     * NOTE: stack_base refers to the HIGHEST address of
     *       stack.
	 */

	task->stack_base = get_new_stack(info);
	*((uint32_t*)(task->stack_base-4))= (uint32_t)cleanup;
	task->context.jmp_restorer._eip = (uint32_t)fp;
	task->context.jmp_restorer._ebp = task->stack_base;
	task->context.jmp_restorer._esp = task->stack_base-sizeof(uint32_t);



	/*
	 * TODO: 3. Link new task_t into queue
	 */
	if (dw_inqueue(task) == -1){
		free_stack(task->stack_base);
		free(task);
		return DWT_TID_NONE;
	}else
		return task->tid;
}
Пример #10
0
int main (int argc, char **argv) {
   program_name = basename (argv[0]);
   scan_options (argc, argv);
   stack *stack = new_stack ();
   bool quit = false;
   yy_flex_debug = false;
   while (! quit) {
      int token = yylex();
      if (token == YYEOF) break;
      switch (token) {
         case NUMBER: do_push (stack, yytext); break;
         case '+': do_binop (stack, add_bigint); break;
         case '-': do_binop (stack, sub_bigint); break;
         case '*': do_binop (stack, mul_bigint); break;
         case 'c': do_clear (stack); break;
         case 'f': do_print_all (stack); break;
         case 'p': do_print (stack); break;
         case 'q': quit = true; break;
         default: unimplemented (token); break;
      }
   }
   yycleanup();
   DEBUGF ('m', "EXIT %d\n", exit_status);
   do_clear(stack);
   free_stack(stack);
   return EXIT_SUCCESS;
}
Пример #11
0
int clean_population()
/* Frees memory for all individuals in population and for the global
   population itself. */
{
     int current_id;

     if (NULL != global_population.individual_array)
     {
        current_id = get_first();
        while(current_id != -1)
        {
           remove_individual(current_id);
           current_id = get_next(current_id);
        }
        
        free_stack(&global_population.free_ids_stack);
        free(global_population.individual_array);

        global_population.individual_array = NULL;
        global_population.size = 0;
        global_population.last_identity = -1;
        
     }
     
        
     return (0);
}
Пример #12
0
int run_helper_thread(int (*proc)(void *), void *arg, unsigned int flags,
		      unsigned long *stack_out)
{
	unsigned long stack, sp;
	int pid, status, err;

	stack = alloc_stack(0, __cant_sleep());
	if (stack == 0)
		return -ENOMEM;

	sp = stack + UM_KERN_PAGE_SIZE - sizeof(void *);
	pid = clone(proc, (void *) sp, flags, arg);
	if (pid < 0) {
		err = -errno;
		printk(UM_KERN_ERR "run_helper_thread : clone failed, "
		       "errno = %d\n", errno);
		return err;
	}
	if (stack_out == NULL) {
		CATCH_EINTR(pid = waitpid(pid, &status, __WCLONE));
		if (pid < 0) {
			err = -errno;
			printk(UM_KERN_ERR "run_helper_thread - wait failed, "
			       "errno = %d\n", errno);
			pid = err;
		}
		if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0))
			printk(UM_KERN_ERR "run_helper_thread - thread "
			       "returned status 0x%x\n", status);
		free_stack(stack, 0);
	} else
		*stack_out = stack;
	return pid;
}
Пример #13
0
int main (int argc, char **argv) {
   program_name = basename (argv[0]);
   scan_options (argc, argv);
   stack *stack = new_stack ();
   token *scanner = new_token (stdin);
   for (;;) {
      int token = scan_token (scanner);
      if (token == EOF) break;
      switch (token) {
         case NUMBER: do_push (stack, peek_token (scanner)); break;
         case '+': do_binop (stack, add_bigint); break;
         case '-': do_binop (stack, sub_bigint); break;
         case '*': do_binop (stack, mul_bigint); break;
         case 'c': do_clear (stack); break;
         case 'f': do_print_all (stack); break;
         case 'p': do_print (stack); break;
         default: unimplemented (token); break;
      }
   }
   
   do_clear(stack);
   free_stack(stack);
   free_token(scanner);
   DEBUGF ('m', "EXIT %d\n", exit_status);
   return EXIT_SUCCESS;
}
Пример #14
0
main()
{
  IS is;
  Queue q;
  Stack s;
  Dllist l;
  int i;
  Jval j;

  is = new_inputstruct(NULL);

  while (get_line(is) > 0) {
    q = new_queue();
    s = new_stack();
    l = new_dllist();
    for (i = 0; i < strlen(is->fields[0]); i++) {
      queue_enqueue(q, new_jval_c(is->fields[0][i]));
      stack_push(s, new_jval_c(is->fields[0][i]));
      dll_append(l, new_jval_c(is->fields[0][i]));
      dll_prepend(l, new_jval_c(is->fields[0][i]));
    }
    while (!queue_empty(q)) {
      j = queue_dequeue(q); printf("%c", j.c);
      j = stack_pop(s); printf("%c", j.c);
      printf("%c", l->flink->val.c); dll_delete_node(l->flink);
      printf("%c", l->flink->val.c); dll_delete_node(l->flink);
      printf(" ");
    }
    printf("\n");
    free_queue(q);
    free_stack(s);
    free_dllist(l);
  }
}
Пример #15
0
int run_helper_thread(int (*proc)(void *), void *arg, unsigned int flags, 
		      unsigned long *stack_out, int stack_order)
{
	unsigned long stack, sp;
	int pid, status;

	stack = alloc_stack(stack_order, um_in_interrupt());
	if(stack == 0) return(-ENOMEM);

	sp = stack + (page_size() << stack_order) - sizeof(void *);
	pid = clone(proc, (void *) sp, flags | SIGCHLD, arg);
	if(pid < 0){
		printk("run_helper_thread : clone failed, errno = %d\n", 
		       errno);
		return(-errno);
	}
	if(stack_out == NULL){
		CATCH_EINTR(pid = waitpid(pid, &status, 0));
		if(pid < 0){
			printk("run_helper_thread - wait failed, errno = %d\n",
			       errno);
			pid = -errno;
		}
		if(!WIFEXITED(status) || (WEXITSTATUS(status) != 0))
			printk("run_helper_thread - thread returned status "
			       "0x%x\n", status);
		free_stack(stack, stack_order);
	}
        else *stack_out = stack;
	return(pid);
}
Пример #16
0
/* Generate the maze
 *
 * Parameter(s): maze - maze cells
 *               w    - maze width
 *               h    - maze height
 *
 * Return: 0 on allocation error
 *         1 otherwise
 */
int generate(int **maze, const int w, const int h)
{
	struct stack *st = NULL;
	int x, y, tmpx, tmpy;

	/* Seed rand() for rand_neighbour() */
	srand((unsigned int) time(NULL));

	/* Maze generation starts at bottom right corner. It's easiest to solve
	 * the maze in the same 'way' it was generated, and since we believe
	 * people intuitively will start at the top left corner, we start it
	 * opposite of that (bottom right) */
	x = w - 2;
	y = h - 2;

	while (1) {
		maze[y][x] = VISIT;
		tmpx = x;
		tmpy = y;

		if (rand_neighbour(maze, &x, &y, w, h)) {
			if (!push(&st, tmpx, tmpy)) {
				free_stack(&st);

				return 0;
			}
		} else {
			/* If no neighbour, we backtrack to the mother cell */
			x = st->x;
			y = st->y;

			pop(&st);

			/* End generation if we can't backtrack further */
			if (st->next == NULL) {
				break;
			}
		}
	}
	free_stack(&st);

	/* Mark exit and entrance */
	maze[1][0] = VISIT;
	maze[h - 2][w - 1] = VISIT;

	return 1;
}
Пример #17
0
void
rust_task::new_stack(size_t requested_sz) {
    LOG(this, mem, "creating new stack for task %" PRIxPTR, this);
    if (stk) {
        ::check_stack_canary(stk);
    }

    // The minimum stack size, in bytes, of a Rust stack, excluding red zone
    size_t min_sz = thread->min_stack_size;

    // Try to reuse an existing stack segment
    while (stk != NULL && stk->next != NULL) {
        size_t next_sz = user_stack_size(stk->next);
        if (min_sz <= next_sz && requested_sz <= next_sz) {
            LOG(this, mem, "reusing existing stack");
            stk = stk->next;
            return;
        } else {
            LOG(this, mem, "existing stack is not big enough");
            stk_seg *new_next = stk->next->next;
            free_stack(stk->next);
            stk->next = new_next;
            if (new_next) {
                new_next->prev = stk;
            }
        }
    }

    // The size of the current stack segment, excluding red zone
    size_t current_sz = 0;
    if (stk != NULL) {
        current_sz = user_stack_size(stk);
    }
    // The calculated size of the new stack, excluding red zone
    size_t rust_stk_sz = get_next_stack_size(min_sz,
                                             current_sz, requested_sz);

    if (total_stack_sz + rust_stk_sz > thread->env->max_stack_size) {
        LOG_ERR(this, task, "task %" PRIxPTR " ran out of stack", this);
        fail();
    }

    size_t sz = rust_stk_sz + RED_ZONE_SIZE;
    stk_seg *new_stk = create_stack(&local_region, sz);
    LOGPTR(thread, "new stk", (uintptr_t)new_stk);
    new_stk->task = this;
    new_stk->next = NULL;
    new_stk->prev = stk;
    if (stk) {
        stk->next = new_stk;
    }
    LOGPTR(thread, "stk end", new_stk->end);

    stk = new_stk;
    total_stack_sz += user_stack_size(new_stk);
}
Пример #18
0
static int free_stack( msgc_stackseg_t *stack )
{
  int n = 0;

  if (stack != 0) {
    n = 1 + free_stack( stack->next );
    gclib_free( stack, sizeof( msgc_stackseg_t ) );
  }
  return n;
}
Пример #19
0
Файл: main.c Проект: Ahmed-Z/wf
void parse_input(FILE* input, list__t* w_list)
{
    char c;
    char* str;
    int strlen = 0;

    link__t* w_link;
    
    int str_exist;
    
    stack__t* stack = new_stack();
    
    
    for(;;){
        c = fgetc(input);
        if(isalnum(c) && !isspace(c)){
            stack_push(stack , c);
        }else if(c  != EOF){

            if(stack->next != NULL){//stack empty do nothing
                strlen = stack_size(stack);
                str = xmalloc( strlen + 1 );
                str[strlen] = stack->c;// the head has the value '\0'
                while(stack->next != NULL)
                    str[--strlen] = tolower(stack_pop(stack));
                w_list->word_count ++;
                /**
                 * Loop through the list and check if the word already exist
                 */
                
                link__t* w_link = w_list->first;
                while( w_link != NULL ){
                    
                    if( !strcmp ( str , w_link->word->text) ){
                        w_link->word->count+=1;
                        break;
                    }
                    
                  w_link = w_link->next;      
                }
                
                if(w_link == NULL)
                    insert__last(w_list, str);
                
                free(str);

            }
        }else
            break;
        
    }
    
   free_stack(&stack);       
    
}
Пример #20
0
void main()
{
 clrscr();
  STACK *p1=NULL,*p2=NULL;
  int a,i;
  printf("Vvedit' 10 chisel: ");
  for(i=0;i<10;i++)
   {
	scanf("%d",&a);
	if(a%2==0) put(p1,a);
	else put(p2,a);
   }
  printf("\nParni: ");
  views(p1);
  printf("\nNeparni: ");
  views(p2);
  free_stack(p1);
  free_stack(p2);
 getch();
}
Пример #21
0
void free_task_que(Task_que_t *tq)
{
  char *cid = tq->dummycid;
  log_printf(15, "free_task_que: cid=%s\n",cid);
 
  
  free_stack(tq->io_que[TASK_READ_QUE], 0);
  free_stack(tq->io_que[TASK_WRITE_QUE], 0);

  pthread_mutex_destroy(&(tq->qlock));

//  free(tq->cid);   //** This is done in outside by task_key_destroy

  free(tq);

  log_printf(15, "free_task_que: End cid=%s\n",cid);
  free(cid);
  
//  g_slice_free(Task_que_t, tq);
}
Пример #22
0
static void
free_thread(struct pthread *curthread, struct pthread *thread)
{
	free_stack(&thread->attr);
	if ((thread->attr.flags & PTHREAD_SCOPE_SYSTEM) != 0) {
		/* Free the KSE and KSEG. */
		_kseg_free(thread->kseg);
		_kse_free(curthread, thread->kse);
	}
	_thr_free(curthread, thread);
}
Пример #23
0
void
rust_task::cleanup_after_turn() {
    // Delete any spare stack segments that were left
    // behind by calls to prev_stack
    I(thread, stk);
    while (stk->next) {
        stk_seg *new_next = stk->next->next;
        free_stack(stk->next);
        stk->next = new_next;
    }
}
Пример #24
0
void 
die(const char *message, struct Stack *stack)
{
	if(errno) {
		perror(message);
	} else {
		printf("ERROR: %s\n", message);
	}
	free_stack(stack);
	exit(1);
}
Пример #25
0
int generate( char maze[][ MAP_WSIZE ], const int w, const int h) {
  struct stack *st = NULL;
  int x, y, tmpx, tmpy;

  srand( time( 0 ) );

  x = w - 2;
  y = h - 2;

  while( 1 ){
    maze[y][x] = VISIT;
    tmpx = x;
    tmpy = y;

    if (rand_neighbour(maze, &x, &y, w, h)) {
      if( push(&st, tmpx, tmpy)) {
        free_stack(&st);

        return 0;
      }
    } else {
      /* If no neighbour, we backtrack to the mother cell */
      x = st->x;
      y = st->y;

      pop( &st );

      /* End generation if we can't backtrack further */
      if( st->next == 0 ) {
        break;
      }
    }
  }
  free_stack( &st );

  /* Mark exit and entrance */
  maze[1][0] = PLAYER;
  maze[h - 2][w - 1] = MONSTER;

  return 1;
}
Пример #26
0
int main()
{
	int n, in, i;
	bool flag = true;
	list *stack,*back;
	
	scanf("%d",&n);
	init_stack(&stack);
	back = NULL;
	
	while(n)
	{
		for(i=0 ; i<n ; i++)
		{
			scanf("%d",&in);
			
			/*caso nao seja uma matrioskha, eh possivel que tenha sobrado conteudo na entrada padrao*/
			if(flag)
			{
				/*caso seja o brinquedo que fecha o q esta no topo da pilha*/
				if(back && back->n < 0 &&  back->n == -in)
				{
					pop_back(&stack);
					
					if(!stack_empty(stack))
					{
						back = check_back(&stack);
						back->tam+=in;/*incrementa o tamanho acumulado naquele brinquedo*/
						
						/*caso nao atenda a condicao do tamanho, pare de considerar a leitura*/
						if(back->tam >= -back->n)
							flag  = false;
					}
				}
				else
					push_back(in,&stack);
				
				back = check_back(&stack);
			}
		}
		
		printf("%s\n",(stack_empty(stack))?(":-) Matrioshka!"):(":-( Tente novamente."));
		
		/*reinicializa as variaveis para nova operacao*/
		free_stack(&stack);
		flag = true;
		back = NULL;
		
		scanf("%d",&n);
	}
	
	return 0;
}
Пример #27
0
// List directories in depth first order
void recursive_list (char *path) {
   stack = new_stack ();
   push_stack (stack, path);
   for (;;) {
      char *dir = pop_stack (stack);
      printf ("%s:\n", dir);
      list (dir);
      if (is_empty_stack (stack)) break;
      printf ("\n");
   }
   free_stack (stack);
}
Пример #28
0
void
rust_task::delete_all_stacks() {
    I(thread, !on_rust_stack());
    // Delete all the stacks. There may be more than one if the task failed
    // and no landing pads stopped to clean up.
    I(thread, stk->next == NULL);
    while (stk != NULL) {
        stk_seg *prev = stk->prev;
        free_stack(stk);
        stk = prev;
    }
}
Пример #29
0
void assert_empty() {
  Stack *stack = create_stack();
  assert(stack_empty(stack) == 1);

  stack_push(stack, 778);
  assert(stack_empty(stack) == 0);

  stack_pop(stack);
  assert(stack_empty(stack) == 1);

  free_stack(stack);
  printf("✓ assert_empty\n");
}
Пример #30
0
// @breadth_order : The other of breadth first visit is the order of node allocation
GraphHandle build_graph_with_cycles(uint32_t size) {
  GraphHandle graph = build_graph_dag(size);
  Stack stack = build_stack(graph.vertex_count);
  VisitorState visit_state = { .user_state = &stack };

  // we are going to mutate the graph while we traverse it
  // to avoid messing with the traversal, we mutate the nodes on our way out
  two_way_depth_first_traversal((Node*)graph.root, &visit_state, 
      build_graph_with_cycles_in_helper, build_graph_with_cycles_out_helper);

  free_stack(&stack);
  return graph;
}