Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- typedef struct list{
- char nome[81];
- char mat[8];
- char turma;
- float p1;
- float p2;
- float p3;
- list* next;
- }Lista;
- Lista* new_list(){
- return NULL;
- }
- Lista* lst_insereord (Lista* lst, char* nome, char* matricula, char turma, float p1, float p2, float p3){
- Lista* new_l;
- Lista* ant = NULL;
- Lista* p = lst;
- while(p != NULL && strcmp(nome,p->nome)>=0){
- ant = p;
- p = p->next;
- }
- new_l = (Lista*)malloc(sizeof(Lista));
- strcpy(new_l->nome,nome);
- strcpy(new_l->mat,matricula);
- new_l->p1 = p1;
- new_l->p2 = p2;
- new_l->p3 = p3;
- new_l->turma = turma;
- if(ant == NULL){
- new_l->next = lst;
- lst = new_l;
- }
- else{
- new_l->next = ant->next;
- ant->next = new_l;
- }
- return lst;
- }
- void lst_print(Lista* lst){
- Lista* aux;
- for(aux = lst; aux!=NULL; aux = aux->next){
- printf("Conteudo %s + %s\n", aux->nome, aux->mat);
- }
- }
- int lst_void (Lista* lst){
- return (lst == NULL);
- }
- Lista* lst_search (Lista* lst, char* nome){
- Lista* search;
- for(search = lst; search!=NULL; search = search->next){
- if(strcmp(nome, search->nome) == 0){
- return search;
- }
- }
- return NULL;
- }
- Lista* lst_remove (Lista* lst, char* nome){
- Lista* anterior = NULL;
- Lista* aux = lst;
- while(aux != NULL && strcmp(nome,aux->nome) != 0){
- anterior = aux;
- aux = aux->next;
- }
- if(aux == NULL){
- return lst;
- }
- if(anterior == NULL){
- lst = aux->next;
- }
- else{
- anterior->next = aux->next;
- }
- printf("%d Desalocado com Sucesso!\n",aux->nome);
- free(aux);
- return lst;
- }
- Lista* lst_copys(Lista* lst){
- Lista* p = lst;
- Lista* new_l = new_list();
- for(p = lst; p != NULL; p = p->next){
- new_l = lst_insereord(new_l,p->nome,p->mat,p->turma,p->p1,p->p2,p->p3);
- }
- return new_l;
- }
- void lst_destroy(Lista* lst){
- Lista* aux = lst;
- while(aux != NULL){
- Lista* t = aux->next;
- free(aux);
- aux = t;
- }
- }
- int main(void){
- Lista* list;
- Lista* copy;
- list = new_list();
- copy = new_list();
- char nome[81],mat[81];
- for(int i=0; i<3; i++){
- fgets(nome,81,stdin);
- fgets(mat,81,stdin);
- list = lst_insereord(list,nome,mat,'1',2.0,3.0,4.0);
- }
- copy = lst_copyss(list);
- lst_print(copy);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement