/** *@brief: Cria uma nova mensagem e acrescenta essa mensagem na posicao final do vector de utilizadores. */ void send(LINK *vec, FILA *filas) { int e, r; TEXTO string; SMS msg; LINK node; char aux; getchar(); getchar(); /*4 comandos para ler 'end_', dados que nao seram*/ getchar(); /*necessarios na continuidade do programa.*/ getchar(); e = (((int)getchar())-48); /*transforma o caracter relativo ao utilizador num inteiro.*/ while ((aux = getchar()) != ' ') /*ciclo que enquanto nao apanha o \n transforma os caraceteres correspontentes ao utilizador num inteiro.*/ e = e*10 + (((int)aux) - 48); r = (((int)getchar())-48); /*transforma o caracter relativo ao utilizador num inteiro.*/ while ((aux = getchar()) != ' ') /*ciclo que enquanto nao apanha o \n transforma os caraceteres correspontentes ao utilizador num inteiro.*/ r = r*10 + (((int)aux) - 48); string = recebeTexto(); /*Le o texto correspondente a mensagem.*/ msg = criaMensagem(e, r, string); /*Cria um ponteiro para uma estrutura MENSAGEM, que comtem o emissor, o receptor .*/ node = criaNode(msg); acrecentaNode(vec, filas, r, node); }
void send(User ArrayUsers) { char input[CRCTRS]; int sender, receiver; link last; link first; scanf("%d%d ", &sender, &receiver); /*guarda o 'e' e o 'r'*/ fgets(input, CRCTRS, stdin); /*guarda o texto da mensagem em input*/ if (isEmpty(ArrayUsers, receiver)) { first = criaNode(criaMensagem(sender,receiver,input)); ArrayUsers[receiver].head_queue = first; ArrayUsers[receiver].tail_queue = first; }else{ last = criaNode(criaMensagem(sender,receiver,input)); ArrayUsers[receiver].tail_queue -> next = last; ArrayUsers[receiver].tail_queue = last; } }
void inserirPrimeiro(Lista* lista, int valor){ Node* novoNo = criaNode(); Node* noAux; novoNo->valor = valor; novoNo->pProx = lista->pPrimeiro; novoNo->pAnt = NULL; lista->pPrimeiro = novoNo; noAux = lista->pPrimeiro; if(lista->pUltimo == NULL){ lista->pUltimo = lista->pPrimeiro; }else{ noAux = noAux->pProx; noAux = noAux->pAnt; noAux = novoNo; } lista->qtde++; }
void inserirN(Lista *lista, int valor, int pos){ Node* noAux; Node* novoNo; noAux = lista->pPrimeiro; int cont = 1; while (cont < pos) { noAux = noAux->pProx; cont++; } novoNo = criaNode(); novoNo->valor = valor; novoNo->pAnt = noAux; //anterior do novo é o aux novoNo->pProx = noAux->pProx; //o proximo do novo é o prox do auxiliar (aux->pProx) noAux->pProx->pAnt = novoNo; // prox do novo nó recebe o novo nó como anterior noAux->pProx = novoNo; // prox do nó aux é o novoNó lista->qtde ++; }
Node* inserirNo(int valor){ Node* novoNo = criaNode(); novoNo->valor = valor; return novoNo; }