Skip to content

Commit

Permalink
alteracoes no add // criando outra funcao para ajudar no add
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaian-k committed Jun 25, 2022
1 parent 5e82389 commit f37ccce
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 27 deletions.
27 changes: 10 additions & 17 deletions abb.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
//imports
#include <stdio.h>
#include <stdlib.h>


//struct
typedef struct abb_node {
//Dados iniciais da encomenda de um livro
int id; //identificador

char *nome_aluno;
int matricula;
char *descricao;
Expand All @@ -14,6 +17,9 @@ typedef struct abb_node {
} Abb_node; Abb_node *root = NULL;


//fuctions


Abb_node *buscar(int id, Abb_node *aux){
if (aux != NULL){
if (aux->id == id){return aux;}
Expand All @@ -26,25 +32,12 @@ Abb_node *buscar(int id, Abb_node *aux){
else {return NULL;}}


void add_abb(int id, char *nome_aluno, int matricula, char *descricao){
Abb_node *aux = buscar(id, root);

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

else {
Abb_node *novo = malloc(sizeof(Abb_node));
novo->id = id;
novo->nome_aluno = nome_aluno;
novo->matricula = matricula;
novo->descricao = descricao;
novo->left = NULL; novo->right = NULL;

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

else {
if (id < aux->id){aux->left = novo;}

else {aux->right = novo;}}}}
if (id < aux->id){aux->left = new;}
else {aux->right = new;}}}


Abb_node *remover_abb(Abb_node *root, int id){
Expand Down
4 changes: 4 additions & 0 deletions fila_prioridade.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
//imports
#include <stdio.h>
#include <stdlib.h>


//structs
typedef struct pedido {
int identificador;
char *nome_aluno;
Expand All @@ -18,6 +20,8 @@ typedef struct fifop_node {
Fifop_node *fifop_start = NULL; Fifop_node *fifop_last = NULL; int fifop_tam = 0;


//fuctions

void add_fila(int identificador, char *nome_aluno, int prioridade){
Pedido *p = malloc(sizeof(Pedido));
p->identificador = identificador;
Expand Down
30 changes: 20 additions & 10 deletions fuctions_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,26 @@


void encomendar(){
printf(" Digite o nome do aluno:\n");
char *nome = malloc(sizeof(char)); scanf(" %[^\n]s", nome);

//... matricula e descricao.. Dados iniciais da encomenda de um livro
printf(" Digite a matricula do aluno:\n");
int matricula = malloc(sizeof(int)); scanf("%d", &matricula);
printf(" Escreva a descricao do livro:\n");
char *descricao = malloc(sizeof(char)); scanf(" %[^\n]s", descricao);

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

add_abb(id, nome, matricula, descricao);}
Abb_node *aux = buscar(id, root);
Abb_node *new = malloc(sizeof(Abb_node));

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

else {
new->id = id;

printf(" Digite o nome do aluno:\n");
char *nome = malloc(sizeof(char)); scanf(" %[^\n]s", new->nome_aluno);

//... matricula e descricao.. Dados iniciais da encomenda de um livro
printf(" Digite a matricula do aluno:\n");
int matricula; scanf("%d", &new->matricula);

printf(" Escreva a descricao do livro:\n");
char *descricao = malloc(sizeof(char)); scanf(" %[^\n]s", new->descricao);

new->left = NULL; new->right = NULL;
add_abb(new, aux, id);}}
Binary file modified principal
Binary file not shown.

0 comments on commit f37ccce

Please sign in to comment.