main() { int element , ch ; queue q; char * mnu[] = { "Insertion", "Deletion", "Display", "Exit", }; q.rear = -1; q.front = 0; while(1){ ch = menu(mnu,4,20,10,"****Choices****") ; switch(ch){ case 1:puts("Enter the element to be inserted"); scanf("%d",&element); qInsert( &q , element ); break; case 2:if (!isEmpty(&q) ){ qDelete( &q , &element ); printf("The deleted Element is %d\n ",element ); } else printf("Queue Under Flow "); break; case 4:exit(); } qDisplay(&q); puts("*************** Press any key to continue ********************** "); getch(); } }
/** * This function crosses a connected component * and calculates the number of black boxes. * * @param i Current y coordinate * @param j Current x coordinate * @param matrix Binary matrix * @param mark Matrix of marks * * @return Number of black boxes */ void crossCC(int y, int x, t_cc_elt *elt, t_matrix *matrix, char **mark) { int i, j, kmin, kmax, pmin, pmax, first; int pix_count; int xtmp, ytmp; t_coordinate *coord, *res; t_box_coordinate *minmax; t_queue **q; pix_count = 1; q = NULL; q = (t_queue **)wcalloc(1, sizeof(t_queue *)); xtmp = x; ytmp = y; minmax = wcalloc(1, sizeof(t_box_coordinate)); minmax->xmin = x; minmax->xmax = x; minmax->ymin = y; minmax->ymax = y; first = 1; do { if (!first) { res = qDequeue(q); if (res != NULL) { xtmp = res->x; ytmp = res->y; } } kmin = ytmp-1; if (kmin < 0) kmin = 0; kmax = ytmp+1; if (kmax >= matrix->nbrows) kmax = matrix->nbrows - 1; for (i=kmin; i <= kmax; i++) { pmin = xtmp-1; if (pmin < 0) pmin = 0; pmax = xtmp+1; if (pmax >= matrix->nbcols) pmax = matrix->nbcols - 1; for (j=pmin; j <= pmax; j++) { if ((matrix->data[i][j] == 1) && (mark[i][j] == 'o')) { coord = wmalloc(sizeof(t_coordinate)); coord->x = j; coord->y = i; qEnqueue(q, coord); mark[i][j] = 'x'; updateMinMax(minmax, j, i); pix_count++; } } } first = 0; } while (*q != NULL); elt->coord = *minmax; elt->nbpix = pix_count; qDelete(q); wfree(q); }