Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "To-Do.h"
- #include "fila.h"
- #include "lista.h"
- #include "pilha.h"
- int main(){
- Atividade activity;
- Fila f;
- Lista l;
- Pilha p;
- int op, n_tarefa=0;
- char ativi[65];
- printf("Hello to To-Do Pendulares!\n");
- printf("1 - Criar uma atividade\n"
- "2 - Vizualizar uma atividade");
- scanf("%d", &op);
- switch(op){
- case 1:
- nova_tarefa(n_tarefa);
- criar_atividade(&l, activity, n_tarefa);
- n_tarefa++;
- break;
- case 2:
- printf("Digite o titulo da tarefa que deseja vizualizar:\n");
- scanf("%s", ativi);
- vizualizar_atividade(&l, ativi);
- }
- }
- =============================To_do.h====================================
- #ifndef TO-DO_H_INCLUDED
- #define TO-DO_H_INCLUDED
- #include <stdlib.h>
- #include <stdio.h>
- #include "lista.h"
- #include "fila.h"
- #include "pilha.h"
- typedef struct{
- char titulo [65]; //titulo da tarefa;
- char descricao [257]; //descrição da tarefa;
- char data [11]; //data limite para realização da tarefa, no formato DDMMAAAA; D-dia, M-mês, A-ano;
- int prioridade; // 1 - baixa, 2 - média, 3 - alta;
- int status; //0 - concluida, 1 - em andamento, 2 - pendente, 3 atrazada;
- }Atividade;
- typedef struct Celula{
- Atividade dado; //dado passa a ser do tipo Atividade, contendo todos os seus atribuitos;
- struct Celula *prox; //ponteiro para a proxima celula;
- }Celula;
- void nova_tarefa(int n){
- printf("Titulo da tarefa:\n");
- scanf("%s", Atividade[n].titulo);
- printf("Descricao da Tarefa:\n");
- scanf("%s", Atividade[n].descricao);
- printf("Data da Tarefa:\n");
- scanf("%s", Atividade[n].data);
- printf("Prioridade:\n"
- "1 para baixa;\n"
- "2 para media;\n"
- "3 para alta;\n");
- scanf("%d", Atividade[n].prioridade);
- printf("Status\n"
- "0 - concluida;\n"
- "1 - em andamento;\n"
- "2 - pendente;\n"
- "3 - atrazada;\n");
- }
- void criar_atividade(Lista *l, Atividade activity, int n){
- enqueue(l, activity[n]);
- }
- void vizualizar_atividade(Lista *l, char ativi){
- vizualizar(l, ativi);
- }
- #endif // TO-DO_H_INCLUDED
- ====================================lista.h=============================
- #ifndef LISTA_H_INCLUDED
- #define LISTA_H_INCLUDED
- #include <stdlib.h>
- #include <stdio.h>
- #include <stdbool.h>
- #include "To-Do.h"
- typedef struct Celula{
- Atividade dado; //O dado da Celula é do tipo Atividade;
- struct Celula *prox;
- }Celula;
- typedef struct Lista{
- Celula *inicio, *fim;
- int tam;
- }Lista;
- void create_lista(Lista *l){
- Celula *temp = (Celula*)malloc(sizeof(Celula));
- temp->prox = NULL;
- l->inicio = l->fim = temp;
- l->tam = 0;
- }
- void add(Lista *l, Atividade dado){
- Celula *temp = (Celula*)malloc(sizeof(Celula));
- temp->prox = NULL;
- temp->dado = dado;
- l->fim->prox = temp;
- l->fim = temp;
- l->tam++;
- }
- int remove_at(Lista *l, int pos){
- if(pos < 0 || pos >= l->tam )
- return -1;
- Celula *ant = l->inicio;
- for(int i=0; i<pos;i++)
- ant = ant->prox;
- Celula *temp = ant->prox;
- Atividade dado = temp->dado;
- ant->prox = temp->prox;
- if(ant->prox == NULL)
- l->fim = ant;
- free(temp);
- l->tam--;
- return dado;
- }
- void print_lista(Lista l){
- printf("\nSize: %d\n", l.tam);
- Celula *temp = l.inicio->prox;
- int i=0;
- while(temp!=NULL){
- printf("|%s|\n", temp->dado.titulo);
- printf("%s\n", temp->dado.descricao);
- printf("%s\n", temp->dado.data);
- printf("%d\n", temp->dado.prioridade);
- printf("%s\n", temp->dado.status);
- temp = temp->prox;
- i++;
- }
- }
- void vizualizar(Lista *l, char ativi){
- Celula *temp = l.inicio->prox;
- while(strcmp(l->dado.titulo, ativi) !=0){ //irá comparar o titulo da atividade que o usuarios quer
- temp = temp->prox; //vizualizar e enquanto for diferente ele passa aiante para a proxima celula
- }
- printf("|%s|\n", temp->dado.titulo);
- printf("%s\n", temp->dado.descricao);
- printf("%s\n", temp->dado.data);
- printf("%d\n", temp->dado.prioridade);
- printf("%s\n", temp->dado.status);
- }
- void destroy_lista(Lista *l){
- while(l->inicio != l->fim)
- remove_at(l, 0);
- free(l->inicio);
- }
- #endif // LISTA_H_INCLUDED
- ========================================fila.h===================================
- #ifndef FILA_H_INCLUDED
- #define FILA_H_INCLUDED
- #include <stdlib.h>
- #include <stdio.h>
- #include <stdbool.h>
- #include "To-do.h"
- typedef struct Celula{
- Atividade dado; //O dado da Celula é do tipo Atividade;
- struct Celula *prox;
- }Celula;
- typedef struct{
- Celula *inicio, *fim;
- int tam;
- }Fila;
- void create_fila(Fila *f){
- f->inicio = f->fim = (Celula *)malloc(sizeof(Celula));
- f->tam = 0;
- }
- bool is_empty_fila(Fila f){
- return f.inicio == f.fim;
- }
- bool enqueue(Fila *f, Atividade dado){
- Celula *temp = (Celula *)malloc(sizeof(Celula));
- if(temp == NULL)
- return false;
- temp->prox = NULL;
- temp->dado = dado;
- f->fim->prox = temp;
- f->fim = f->fim->prox;
- f->tam++;
- return true;
- }
- int dequeue(Fila *f){
- if(is_empty_fila(*f))
- return -1;
- Celula *temp = f->inicio;
- f->inicio = f->inicio->prox;
- free(temp);
- f->tam--;
- return f->inicio->dado;
- }
- int peek(Fila f){
- if(is_empty_fila(f))
- return -1;
- return f.inicio->prox->dado;
- }
- void print_fila(Fila f){
- printf("\nSize: %d\n", f.tam);
- Celula *temp = f.inicio->prox;
- while(temp!=NULL){
- printf("|%s|\n", temp->dado.titulo);
- printf("%s\n", temp->dado.descricao);
- printf("%s\n", temp->dado.data);
- printf("%d\n", temp->dado.prioridade);
- printf("%s\n", temp->dado.status);
- temp = temp->prox;
- }
- printf("\n");
- }
- void destroy_fila(Fila *f){
- while(!is_empty_fila(*f))
- dequeue(f);
- free(f->inicio);
- }
- #endif // FILA_H_INCLUDED
- =======================================pilha.h================================
- #ifndef PILHA_H_INCLUDED
- #define PILHA_H_INCLUDED
- #include <stdlib.h>
- #include <stdio.h>
- #include <stdbool.h>
- #include "To-Do.h"
- typedef struct Celula{
- Atividade dado; //O dado da Celula é do tipo Atividade;
- struct Celula *prox;
- }Celula;
- typedef struct{
- Celula *topo;
- int tam;
- }Pilha;
- void create_pilha(Pilha *p){
- p->topo = NULL;
- p->tam = 0;
- }
- void push(Pilha *p, Atividade dado){
- Celula *temp = (Celula*)malloc(sizeof(Celula));
- temp->prox = p->topo;
- temp->dado = dado;
- p->topo = temp;
- p->tam++;
- }
- void print_pilha(Pilha p){
- Celula *temp = p.topo;
- printf("\nSize:%d\n", p.tam);
- while(temp!=NULL){
- printf("|%s|\n", temp->dado.titulo);
- printf("%s\n", temp->dado.descricao);
- printf("%s\n", temp->dado.data);
- printf("%d\n", temp->dado.prioridade);
- printf("%s\n", temp->dado.status);
- temp = temp->prox;
- }
- }
- bool is_empty_pilha(Pilha p){
- return p.topo == NULL;
- }
- int pop(Pilha *p){
- if(is_empty_pilha(*p))
- return -1;
- Celula *temp = p->topo;
- p->topo = p->topo->prox;
- Atividade dado = temp->dado;
- free(temp);
- p->tam--;
- return dado;
- }
- void destroy_pilha(Pilha *p){
- while(!is_empty_pilha(*p))
- pop(p);
- }
- #endif // PILHA_H_INCLUDED
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement