Ejemplo n.º 1
0
int main() {
    int i;
    deque_p test = dequeInit(INIT_CAP);

    putchar('\n');
    printf("Address of array beginning: %p\n", (void*)dequeArrayStart(test));


    for(i = 1; i <= INIT_CAP; i++)
        dequeAddBack(test, i);

    putchar('\n');
    printf("Printing deque contents...\n");
    printDeque(test);

    for(i = 0; i < RM_NUM; i++)
        dequeRmFront(test);

    putchar('\n');
    printf("d->beg: %d; d->size: %d\n", test->beg, test->size);

    putchar('\n');
    printf("(After removal) Printing deque contents...\n");
    printDeque(test);

    dequeAddBack(test, 11);
    putchar('\n');
    printf("Printing deque contents...\n");
    printDeque(test);
}
Ejemplo n.º 2
0
void dequeAddFront(deque_p d, TYPE val) {
    if(d->size >= d->cap) {
        putchar('\n');
        printf("Doubling after call to dequeAddFront...\n");
        printf("current contents:\n");
        printDeque(d);
        putchar('\n');
        _dequeDoubleCap(d);
    }

    // Get pointer to front of deque.
    TYPE* front = dequeFront(d);
    // If the pointer to the front is the beginning
    // of the array, set d->beg to d->cap and
    // reset front to point to the next address
    // after the end of the array
    if(front == d->data) {
        d->beg = d->cap;
        front = &(d->data[d->cap]);
    }

    d->beg--;
    *(--front) = val;
    d->size++;
}
Ejemplo n.º 3
0
void dequeAddBack(deque_p d, TYPE val) {
    if(d->size >= d->cap) {
        putchar('\n');
        printf("Doubling after call to dequeAddBack...\n");
        printf("current contents:\n");
        printDeque(d);
        putchar('\n');
        _dequeDoubleCap(d);
    }

    // get pointer to front of deque.
    TYPE* back = dequeBack(d);
    // If pointer to the back is the last
    // position in the array, set back to point
    // to the position just before the first
    // element of the array.
    if(back == &(d->data[d->cap-1]))
        back = --(d->data);

    *(++back) = val;
    d->size++;
}
Ejemplo n.º 4
0
int main()
{
	int i=0;
	int InfoInserir;
	int x, op=-1, valor;
	deque *d;
	system("cls");
	d=(deque*)malloc(sizeof(deque));
	inicializaDeque(d);

	while(op != 0)
	{
		system("pause");
		system("cls");
		printf("\n\n           DEQUE        \n\n");
		printf("( 1 ) Insere pela Direita.\n");
		printf("( 2 ) Insere pela Esquerda.\n");
		printf("( 3 ) Remove pela Direita. \n");
		printf("( 4 ) Remove pela Esquerda.\n");
		printf("( 5 ) Exibe.\n");
		printf("( 6 ) Busca. \n");
		printf("( 7 ) Organiza. \n");
		printf("( 8 ) Limpa Tudo. \n");
		printf("\nTempo na Busca: %f\n", tempoB/CLOCKS_PER_SEC);
		printf("Tempo no Organizar: %f\n", tempoO/CLOCKS_PER_SEC);
		printf("\nInforme a operacao: ");
		scanf("%d", &op);

		switch(op)
		{
			case 1:
			{
				printf("Diga quantos valores deseja inserir pela Direita <-: ");
				scanf("%d", &InfoInserir);
				for(i=InfoInserir; i>0; i--)
					InsereFrent(d,i);
				break;
			}
			case 2:
			{
				printf("Diga quantos valores deseja inserir pela Esquerda ->: ");
				scanf("%d", &InfoInserir);
				for(i=0; i<InfoInserir; i++)
				InsereFund(d,i);
				break;
			}
			case 3:
			{
				if(taVazio(d))
					RetiraFrent(d);
				break;
			}
			case 4:
			{
				if(taVazio(d))
					RetiraFund(d);
				break;
			}
			case 5:
			{
				printDeque(d);
				break;
			}
			case 6:
			{
				printf("Informe valor para busca :");
				scanf("%d", &valor);
				Busca(d,valor);
				break;
			}
			case 7:
			{
				Ordena(d);
				break;
			}
			case 8:
			{
				ApagaTudo(d);
				break;
			}
			default:
			{
				printf("\nErro: Opcao invalida! Informe novamente.\n");
			}

		}
	}

	system("pause");
	return 0;
}