Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct elemento Elemento;
- struct elemento{
- int info;
- Elemento*prox;
- };
- Elemento* lst_cria(void){
- return NULL;
- }
- Elemento* lst_insere(Elemento*lst,int val){
- Elemento*novo = (Elemento*)malloc(sizeof(Elemento));
- novo->info= val;
- novo->prox= lst;
- return novo;
- }
- Elemento* copia(Elemento*lst,Elemento*q){
- Elemento*p;
- q=(Elemento*) malloc(sizeof(Elemento));
- for(p=lst;p!=NULL;p=p->prox){
- for(;q!=NULL;q=q->prox){
- q->prox=(Elemento*) malloc(sizeof(Elemento));
- q->info= p->info;
- q->prox= p->prox;
- }
- }
- }
- void imprime_copia(Elemento*q){
- Elemento*b;
- for(b=q;b!=NULL;b=b->prox){
- printf("copia= %d\n",b->info);
- }
- }
- void imprime(Elemento*lst){
- Elemento*a;
- for(a=lst;a!=NULL;a=a->prox){
- printf("info= %d\n",a->info);
- }
- }
- int main()
- {
- Elemento*lst;
- Elemento*q;
- lst= lst_cria();
- q= lst_cria();
- lst= lst_insere(lst,1);
- lst= lst_insere(lst,3);
- lst= lst_insere(lst,5);
- imprime(lst);
- copia(lst,q);
- imprime_copia(q);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement