Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct list{
- int val;
- list* next;
- }Lista;
- Lista* new_list(){
- return NULL;
- }
- Lista* lst_insere (Lista* lst, int value){
- Lista* new_l = (Lista*)malloc(sizeof(Lista));
- new_l->val = value;
- new_l->next = lst;
- printf("%d Alocado com Sucesso!\n",new_l->val);
- return new_l;
- }
- void lst_print(Lista* lst){
- Lista* aux;
- for(aux = lst; aux!=NULL; aux = aux->next){
- printf("Conteudo %d\n", aux->val);
- }
- }
- int lst_void (Lista* lst){
- return (lst == NULL);
- }
- Lista* lst_search (Lista* lst, int termo){
- Lista* search;
- for(search = lst; search!=NULL; search = search->next){
- if(search->val == termo){
- return search;
- }
- }
- return NULL;
- }
- Lista* lst_remove (Lista* lst, int value){
- Lista* anterior = NULL;
- Lista* aux = lst;
- while(aux != NULL && aux->val != value){
- 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->val);
- free(aux);
- return lst;
- }
- Lista* lst_copy(Lista* lst){
- Lista* p;
- Lista* nl;
- nl = p;
- return nl;
- }
- 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* copia;
- copia = new_list();
- list = new_list();
- list = lst_insere(list,4);
- list = lst_insere(list,8);
- list = lst_insere(list,12);
- copia = lst_copy(list);
- lst_print(copia);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement