void checkout(list *l, customer *c, date *de1, date *de2, char cn[20]) { int bill; total_bill(c, de1, de2); bill = c->total_bill; remov(l, cn); printf("Your total bill is: %d\n",bill); printf("Hope to see you again\n"); if(c->r_type == 1) (single)++; if(c->r_type == 2) (doub)++; (total_rooms)++; }
int ranking(tlista *lista,tplayer player){ int pos=0, saida=-2, i; printSquarShadow(16,3,2,1,255,7,1,8); printSquare(16,3,2,21,4,4,255); color(WHITE, 4); gowrite(43,2,"RANKING"); saida = getPos(*lista,player,&pos); if(saida == 0 ){ inserir(&(*lista),player,1); } else if(saida == 1){ saida=0; saida = inserir(&(*lista),player,pos); if(saida == 0){ /*saída igual a zero indica que a lista/ / esta cheia e é preciso remover o ultimo*/ remov(&(*lista),TAMLISTA); inserir(&(*lista),player,pos); } } if(statusLista(*lista)==1){ color(1, 7); gowrite(37,12,"No scores currently!"); color(BLACK, WHITE); } else{ exibeLista(*lista,20,5,1,7); } color(BLACK, WHITE); getch(); }
void removdupl(userlist *l){ user *davik, *uzvik; int pos = (l->length) - 1; davik = l->head; uzvik = l->tail; while(davik != l->tail->prev) { while(uzvik != davik) { if(strcmp(davik->usrnm, uzvik->usrnm) == 0) { /*Duplicate found here*/ uzvik = uzvik->prev; remov(l, pos); pos--; } else { uzvik = uzvik->prev; pos--; } } uzvik = l->tail; davik = davik->next; pos = (l->length) - 1; } }
int main(int argc, char **argv) { //Identificadores e Atribuições---------- int escolha; int chave; unsigned int retorno; int *ptr; int posi; unsigned int posicao; int flag; struct desc_lista descritor; struct nodo *NODO; NODO = NULL; descritor.tamanho = 0; flag = 1; //------------------------------------- descritor = *init(); for(;;) { system("clear"); printf("Lista Duplamente Encadeada\n 1.Insert\n 2.Get\n 3.Set\n 4.Delete\n 5.Locate\n 6.Length\n 7.Imprimir Nodo\n \n 0.Sair\nESCOLHA: "); do { scanf("%d",&escolha); } while( escolha < 0 || escolha >7); switch(escolha) { case 0: //--Sair printf("\n\nSaindo do programa...\n\n"); exit(0); break; case 1: //--Inserir if(flag == 0 && NODO == NULL && descritor.tamanho > 0) { printf(" Nodo não escolhido.\n"); getchar(); getchar(); break; } printf("\n\n Valor:"); scanf("%d", &chave); retorno = insert(NODO, chave, &descritor); if( retorno == 1) { printf(" O valor foi inserido com sucesso!\n"); flag = 0; } else { printf(" Oops! O valor %d não pode ser inserido na posição %d\n", chave, posicao); } getchar(); getchar(); imprimir(&descritor); getchar(); break; case 2: //--Get printf("\n\nPosição: "); scanf("%d",&posicao); NODO = get(posicao, &descritor); if( NODO == NULL) { printf(" Não exista a posição.\n"); } else { printf(" Retornou.\n"); } getchar(); getchar(); imprimir(&descritor); getchar(); break; case 3: //--Set if(NODO == NULL) { printf(" O nodo não foi escolhido!\n"); } else { printf("\n\n Novo valor:"); scanf("%d", &chave); retorno = set(NODO,&chave,&descritor); if(retorno == 1) { printf(" O valor foi alterado com sucesso.\n"); } else { printf(" O valor não pode ser trocado por causa de um erro.\n"); } } getchar(); getchar(); imprimir(&descritor); getchar(); break; case 4: //--Delete if( NODO == NULL) { printf(" O nodo não foi escolhido!\n"); } else { retorno = remov(NODO,&descritor); if(retorno == 1) { printf(" O valor foi deletado com sucesso.\n"); NODO = NULL; } else { printf(" O valor não pode ser deletado por causa de um erro.\n"); } } getchar(); getchar(); imprimir(&descritor); getchar(); break; case 5: //--Locate if(NODO == NULL) { printf(" O nodo não foi escolhido!\n"); } else { printf("\n\n Valor a procurar:"); scanf("%d", &chave); NODO = locate(chave, NODO); if(NODO == NULL) { printf(" O nodo não foi encontrado.\n"); } else { printf(" Nodo encontrado.\n"); } } getchar(); getchar(); imprimir(&descritor); getchar(); break; case 6: //--Length retorno = length(&descritor); printf("\n\n O tamanho da lista é de %d\n", retorno); getchar(); getchar(); imprimir(&descritor); getchar(); break; case 7: //--Imprimir Nodo retorno = print(NODO); if( retorno == 0) { printf(" O Nodo é nulo.\n"); } getchar(); getchar(); imprimir(&descritor); getchar(); break; default: printf(" Ooops! Você não deveria estar aqui! o.O"); exit(0); } } return 0; }
void schedule() { //cs printf("activated\n"); if(Current_Thread==NULL) // Main Thread was executing previously.. { TERMINATED=0; if(!isempty(&ready_queue)) // If there are more threads... { Current_Thread=top(&ready_queue); //c printf("yes!! %p\n", Current_Thread); Global_id=Current_Thread->thread_id; swapcontext(&Main, &(Current_Thread->threads_context)); } else // If all threads are dead... { //c printf("main is getting set!\n"); setcontext(&Main); } } else //if someother thread was executing... { struct Task* tmp=next(&ready_queue, Current_Thread); //c printf("other way around and %p and current:%p\n", tmp, Current_Thread); if(tmp==NULL) //if this was the last thread in the queue.... { //execute main fn. //c printf("it was null\n"); if(TERMINATED==1) { //c printf("its gone!!\n"); TERMINATED=0; remov(&ready_queue, Global_id); Current_Thread=NULL; setcontext(&Main); } else { struct Task* tmp1=Current_Thread; Current_Thread=NULL; swapcontext(&(tmp1->threads_context), &Main); } } else { struct Task* tmp2=Current_Thread; Current_Thread=tmp; if(TERMINATED==1) { TERMINATED=0; remov(&ready_queue, Global_id); Global_id=tmp->thread_id; //c printf("context set for %p\n", tmp); setcontext(&(tmp->threads_context)); } else { Global_id=tmp->thread_id; //c printf("running:%p\n", tmp); swapcontext(&(tmp2->threads_context), &(tmp->threads_context)); } } } }
void move1(chess *q, int *prloc, int *locinput, char *str) { int *killedpiece; int a, i; if((((locinput[3] == NOKILL) && (strcmp(str, "undo") != 0 && strcmp(str, "undowithoutredo") != 0))) || (((prloc[3] == NOKILL) && (strcmp(str, "undo") == 0 || strcmp(str, "undowithoutredo") == 0)))){ if(locinput[0] != PAWN) { update(q, prloc, locinput);/* Because it will change its position */ } /* For normal case we are putting the piece on new location */ /* For undo case we are putting the piece on old location */ q->p[locinput[1]][locinput[2]].name[1] = rconvertp(locinput[0]); q->p[locinput[1]][locinput[2]].name[0] = concolor(q->state); q->p[locinput[1]][locinput[2]].status = ALIVE; q->p[locinput[1]][locinput[2]].color = q->state; /* For normal case we are making the old location as empty */ /* For undo case we are making the new location empty */ q->p[prloc[1]][prloc[2]].name[0] = q->p[prloc[1]][prloc[2]].name[1] = '_'; q->p[prloc[1]][prloc[2]].status = NOSTATUS; q->p[prloc[1]][prloc[2]].color = NOCOLOR; if(strcmp(str, "undo") == 0 || strcmp(str, "undowithoutredo") == 0) { q->p[locinput[1]][locinput[2]].name[0] = concolor(q->prevstate); q->p[locinput[1]][locinput[2]].color = q->prevstate; /* Done with prloc not for undo */ } else if(strcmp(str, "redo") == 0) { q->p[locinput[1]][locinput[2]].name[0] = concolor(q->state); q->p[locinput[1]][locinput[2]].color = q->state; } else { /* free redo */ if(empty(&q->r) == 0 && strcmp(str, "exp") != 0) { freeredo(q, &q->r); } } } else {/* KILL */ /* For the piece being killed */ a = convertp(q->p[locinput[1]][locinput[2]].name[1]); /* Converts char into int */ if(a != PAWN) { killedpiece = (int *)malloc(sizeof(int) * 4); killedpiece[0] = a; killedpiece[1] = locinput[1]; killedpiece[2] = locinput[2]; killedpiece[3] = NOKILL; remov(q, killedpiece);/* The piece will be removed from the list */ free(killedpiece); } if(locinput[0] != PAWN) { update(q, prloc, locinput);/* Because it is changing its position */ } /* Everything about killedpiece is done and now about moving */ if((strcmp(str, "undo") == 0) || (strcmp(str, "redo") == 0) || (strcmp(str, "undowithoutredo") == 0)) { q->p[locinput[1]][locinput[2]].name[1] = rconvertp(locinput[0]); q->p[locinput[1]][locinput[2]].status = ALIVE; if(strcmp(str, "undo") == 0 || strcmp(str, "undowithoutredo") == 0) { q->p[locinput[1]][locinput[2]].name[0] = concolor(q->prevstate); q->p[locinput[1]][locinput[2]].color = q->prevstate; } else { q->p[locinput[1]][locinput[2]].name[0] = concolor(q->state); q->p[locinput[1]][locinput[2]].color = q->state; } /* Done with prloc not for undo */ /* Restoring the killed piece */ if(strcmp(str, "undo") == 0 || strcmp(str, "undowithoutredo") == 0) { q->p[prloc[1]][prloc[2]].name[0] = concolor(q->state); q->p[prloc[1]][prloc[2]].name[1] = rconvertp(prloc[4]); } else { q->p[prloc[1]][prloc[2]].name[0] = '_'; q->p[prloc[1]][prloc[2]].name[1] = '_'; } q->p[prloc[1]][prloc[2]].status = ALIVE; q->p[prloc[1]][prloc[2]].color = prloc[8]; } else { /* free redo */ if(empty(&q->r) == 0 && strcmp(str, "exp") != 0) { freeredo(q, &q->r); } update(q, prloc, locinput); q->p[prloc[1]][prloc[2]].name[0] = q->p[prloc[1]][prloc[2]].name[1] = '_'; q->p[prloc[1]][prloc[2]].status = NOSTATUS; q->p[prloc[1]][prloc[2]].color = NOCOLOR; q->p[locinput[1]][locinput[2]].name[1] = rconvertp(locinput[0]);/* Converts int to char */ q->p[locinput[1]][locinput[2]].name[0] = concolor(q->state); q->p[locinput[1]][locinput[2]].status = ALIVE; q->p[locinput[1]][locinput[2]].color = q->state; if(locinput[0] != PAWN) { update(q, prloc, locinput); } } } }
static int nfsrmdir(int n, Rpccall *cmd, Rpccall *reply) { chat("rmdir..."); return remov(n, cmd, reply); }