int main(void)
{
    struct stack* stk1 = new_stack();
    struct stack* stk2 = new_stack();

    int i;

    for (i = 0; i < NUM_ITEMS; i++) {
		push(stk1, 200+i);
		push(stk2, 700+i);
    }

    printf("Dump of stack 1:\n");
    
	for (i = 0; i < NUM_ITEMS; i++)
		printf("%d\n", pop(stk1));

    printf("Dump of stack 2:\n");
    
	for (i = 0; i < NUM_ITEMS; i++)
		printf("%d\n", pop(stk2));

    delete_stack(stk1);
    delete_stack(stk2);
    
    return 0;
}
Beispiel #2
0
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <errno.h>
#include "functions.h"
int stack_size = 0; /* stack full size */
int main()
{
	int *A; /* Stack - massive pointer */
	int N = -1; /* stack top pointer */
	int opt; /* switch options */
	int ext_data, add_data; /* extracting and adding data */
	printf("Please, enter stack size : ");
	scanf("%d", &stack_size);
	A = create_stack(stack_size);
	printf("\n");
	while(1)
	{
		interface();
		opt = getchar();
		switch(opt)
		{
			case 'e': ext_data = stack_pop(A,&N); break;
			case 'a': 	printf("Enter adding data:\n");
						scanf("%d", &add_data);
						stack_push(A, &N, add_data);
						break;
			case 'd': N = delete_stack(A); break;
			case 'f': 	printf("Free place in stack: %d\n", free_place(N, stack_size));
						break;
			case 'q': if(N != -2)
						printf("Please, make free stack\n");
					 else
					 	exit(1);
						break;
		}
	}
return 0;
}
Beispiel #3
0
void delete_all(struct node* root, char what, void* val, int number, int stack_n){
	struct node *temp=find(root, what, val,stack_n);
	for (; number > 0; number--){
		temp=find(root, what, val,stack_n);
		if(temp->name=='D')
			free(temp->value);
		if(temp->name=='S')
			delete_stack(root, temp,stack_n);
		re_move(root, temp);
	}
}
Beispiel #4
0
static void
application_cleanup(void) {
    configs_cleanup();
    asset_close();

    audio_cleanup();
    video_cleanup();

    while (!is_stack_empty(states_stack))
        application_back_state();

    delete_stack(states_stack);
}
Beispiel #5
0
int main(int argc, char *argv[])
{
    int i, num;
    if(argc == 2)
    {
        num = atoi(argv[1]);
        build_prime_table(num);
        printf("int primes[%d]={", primes->length);
        for(i = 0; i < primes->length; i++)
        {
            printf(
                "%d%c",
                primes->stuff[i],
                i == primes->length - 1 ? '}' : ','
            );
        }
        printf(";\n");
        delete_stack(&primes);
    }
    return 0;
}
Beispiel #6
0
int main(int argc, char **argv) {
	//printf("n_threads: %d\n", omp_get_num_threads());	

	char * lcs_result = NULL;
	InputInfo * inputInfo = NULL;
	
	// read input
	inputInfo = readInput(argv[1]);
	if(inputInfo == NULL) {
		printf("input info is NULL\n");
		return -1;
	}

	int matx_max = inputInfo->size_x;
	int maty_max = inputInfo->size_y;

	int i,j;


	CellVal **matrix = allocArray(matx_max, maty_max);

	// define the number of cells on the auxiliar matrix
	int block_x_size = (matx_max > 20)?   20 : matx_max / 5;
	int block_y_size = (maty_max > 300)? 300 : maty_max / 5;
	int tabx_max =  matx_max / block_x_size;
	int taby_max =  maty_max / block_y_size;

	CellVal **table = allocArray(tabx_max, taby_max);

	// initialize table: 1 for the sides, 2 for the 1st square, 0 for the rest
	for(i = 0; i < tabx_max; i++) {
		for(j = 0; j < taby_max; j++) {
			if(i==0 && j==0)
				table[i][j] = 2;
			else if(i==0 || j==0)
				table[i][j] = 1;
			else
				table[i][j] = 0;
		}
	}

	// initialize the global vars that are used on the generation of new blocks
	int remainderX         = matx_max % block_x_size;
	int extra_per_cellX    = remainderX / tabx_max;
	extra_remainderX       = remainderX % tabx_max;
	n_mat_coords_per_cellX = block_x_size + extra_per_cellX;

	int remainderY         = maty_max % block_y_size;
	int extra_per_cellY    = remainderY / taby_max;
	extra_remainderY       = remainderY % taby_max;
	n_mat_coords_per_cellY = block_y_size + extra_per_cellY;

	// initialize the block stack with the first block to be processed
	Stack * stack = new_stack(max(tabx_max, taby_max));
	push(stack, new_square(0, 0, matx_max, maty_max, tabx_max, taby_max));
	
	Square * square = NULL; // holds the block for processing
	CellVal x,y;
	int notFinished = 1; // false

#pragma omp parallel private(square, x, y, notFinished)
{	
	notFinished = 1;
	while(notFinished) {
		square = NULL;

		// wait for a block to process
		while(square == NULL && notFinished) {
			#pragma omp critical
			{					
				if(!empty(stack)) {
					square = pop(stack);
					table[square->tabX][square->tabY]++;
				}
			}
			if(square == NULL)
				notFinished = notFinishedTab(table, tabx_max, taby_max);
		}
		
		if(!notFinished)
			break;

		// process the block
		for(x = square->x_min; x < square->x_max; x++) {
			for(y = square->y_min; y < square->y_max; y++) {
				calc(x,y, matrix, inputInfo->X, inputInfo->Y);
			}
		}

		// update the auxiliar table and add to the stack the blocks that now can be processed
		#pragma omp critical
		{
			if(square->tabX + 1 < tabx_max) {
				table[square->tabX + 1][square->tabY]++;
				if(table[square->tabX + 1][square->tabY] == 2) {
					push(stack, new_square(square->tabX + 1, square->tabY, matx_max, maty_max, tabx_max, taby_max));
				}
			}
			if(square->tabY +1 < taby_max) {
				table[square->tabX][square->tabY + 1]++;
				if(table[square->tabX][square->tabY + 1] == 2) {
					push(stack, new_square(square->tabX, square->tabY + 1, matx_max, maty_max, tabx_max, taby_max));
				}
			}
		}

		free(square);
		notFinished = notFinishedTab(table, tabx_max, taby_max);
	}
}
	free(table);
	delete_stack(stack);
	
	//
	lcs_result = lcs(matrix, inputInfo->X, inputInfo->Y, matx_max, maty_max);
	printf("%d\n", matrix[matx_max-1][maty_max-1]);
	printf("%s\n", lcs_result);
	return 0;
}
Beispiel #7
0
int main(void)
{
	int *a = malloc(sizeof(int)), *b = malloc(sizeof(int)), *c = malloc(sizeof(int));
	Stack s = NULL;
    Elem* temp = NULL;
	*a = 12;
    *b = 15;
    *c = 4;

    s = create_stack((void*)a);
    temp = (Elem*) calloc(1, sizeof(Elem));

	printf("1 - create_stack\tLength: %d\n", length_of(s));
    print_list_of_int(s);

	if(!is_empty(s))
	{
		s  = push(s, (void*)b);
	    printf("\n2 - push\tLength: %d\n", length_of(s));
        print_list_of_int(s);
    }
	else
	{
		printf("Unable to allocate a new stack\n");
		return 0;
	}

    s = push(s, (void*)c);
	printf("\n3 - push\tLength: %d\n", length_of(s));
    print_list_of_int(s);

    temp = pop(&s);
    printf("\n4 - pop\tLength: %d\n", length_of(s));
    if(!is_empty(temp))
        printf("temp->data = %d\n", *(int*)temp->data);
    print_list_of_int(s);
    free(temp);
    temp = NULL;

    temp = pop(&s);
    printf("\n5 - pop\tLength: %d\n", length_of(s));
    if(!is_empty(temp));
        printf("temp->data = %d\n", *(int*)temp->data);
    print_list_of_int(s);
    free(temp);
    temp = NULL;

    temp = pop(&s);
    printf("\n6 - pop\tLength: %d\n", length_of(s));
    if(!is_empty(temp));
        printf("temp->data = %d\n", *(int*)temp->data);
    print_list_of_int(s);
    free(temp);
    temp = NULL;

	s  = push(s, (void*)b);
	printf("\n7 - push\tLength: %d\n", length_of(s));
    print_list_of_int(s);

    delete_stack(s);
	free(a);
    free(b);
    free(c);
	return 0;
}
Beispiel #8
0
int main(int argc, char *argv[])
{
	build_prime_table(1000000);
	delete_stack(&primes);
	return 0;
}