Skip to content

Commit

Permalink
add a base para o gerador de id
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaian-k committed Jun 26, 2022
1 parent e5efcf0 commit 80c15c1
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
3 changes: 2 additions & 1 deletion abb.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ Abb_node *buscar(int id, Abb_node *aux){


void add_abb(Abb_node *new, Abb_node *aux, int id){
if (aux == NULL){root = new;} //arvore esta vazia
if (aux == NULL){
new->id = 32; root = new;} //arvore esta vazia

else {
if (id < aux->id){aux->left = new;}
Expand Down
31 changes: 26 additions & 5 deletions fuctions_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,35 @@
#include "fila_prioridade.h"
//#include "fila_pre_cadastrados.h"

//create variables
int add_esq_ou_dir = 0;

void encomendar(){
//criar um funcao para gerar id unico (:D)
int id = 0;

Abb_node *aux = buscar(id, root);
//fuctions

int gerador_id(){
if (add_esq_ou_dir == 0){
Abb_node *aux = buscar(0, root);
if (aux != NULL && aux->id >= 0){
add_esq_ou_dir = 1;
return aux->id/2;}}

else {
Abb_node *aux = buscar(64, root);
if (aux != NULL && aux->id <= 64){
add_esq_ou_dir = 0;
return 64-(64-aux->id)/2;}}

return 0;}


void encomendar(){
int id = gerador_id();

Abb_node *new = malloc(sizeof(Abb_node));

Abb_node *aux = buscar(id, root);


if (aux != NULL && aux->id == id){printf("Insercao invalida!\n\n");}

else {
Expand Down
Binary file modified principal
Binary file not shown.
2 changes: 1 addition & 1 deletion principal.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ int main(){
switch (resp){
case 1: //encomendar um livro
//OBS: CRIA GERADOR ID
encomendar(); break;
encomendar(); in_ordem(root); break;

case 2:
remover_encomenda(); break;
Expand Down

0 comments on commit 80c15c1

Please sign in to comment.