Advertisement
Guest User

BICALAB3

a guest
May 26th, 2015
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.34 KB | None | 0 0
  1. /*EL MAIN*/
  2. /*
  3.  * File:   main.c
  4.  * Author: wperezp
  5.  *
  6.  * Created on May 25, 2015, 8:45 PM
  7.  */
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include "ListaConj.h"
  12.  
  13. /*
  14.  *
  15.  */
  16.  
  17. int main() {
  18.     TLista conjunto1, conjunto2, conjunto3;
  19.     Lista_init(&conjunto1); Lista_init(&conjunto2); Lista_init(&conjunto3);
  20.     Lista_insertar(&conjunto1, 1); Lista_insertar(&conjunto1, 3);
  21.     Lista_insertar(&conjunto1, 6); Lista_insertar(&conjunto1, 9);
  22.     Lista_insertar(&conjunto2, 2); Lista_insertar(&conjunto2, 3);
  23.     Lista_insertar(&conjunto2, 5); Lista_insertar(&conjunto2, 6);
  24.     Lista_insertar(&conjunto2, 4); Lista_insertar(&conjunto2, 8);
  25.    
  26.     conjunto3 = conjuntos_Union(&conjunto1, &conjunto2);
  27.     Lista_imprimir(&conjunto3);
  28.    
  29.     return (EXIT_SUCCESS);
  30. }
  31.  
  32.  
  33.  
  34. /*EL LISTACONJ.C*/
  35. struct lista conjuntos_Union(TLista *C1, TLista *C2) {
  36.     TLista conjuntoUnion; Lista_init(&conjuntoUnion);
  37.     TNodo *ptrAux;
  38.     ptrAux = C1->inicio;
  39.     while (ptrAux) {
  40.         Lista_insertar(&conjuntoUnion, ptrAux->elem);
  41.         ptrAux = ptrAux->sig;
  42.     }
  43.     ptrAux = C2->inicio;
  44.     while (ptrAux) {
  45.         Lista_insertar(&conjuntoUnion, ptrAux->elem);
  46.         ptrAux = ptrAux->sig;
  47.     }
  48.     return conjuntoUnion;
  49. }
  50.  
  51.  
  52. //HEADER
  53.  
  54. /*
  55.  * File:   ListaST.h
  56.  * Author: Fernando Alva Manchego
  57.  *
  58.  */
  59.  
  60. #ifndef LISTAST_H
  61. #define LISTAST_H
  62.  
  63. typedef int TElemento;
  64.  
  65. typedef struct nodo{
  66.     TElemento elem;
  67.     struct nodo *sig;
  68. }TNodo;
  69.  
  70. typedef struct lista{
  71.     TNodo *inicio;
  72.     TNodo *fin;
  73.     int numElem;
  74. }TLista;
  75.  
  76.  
  77. /* Crea una lista vacía */
  78. void Lista_init(TLista *);
  79. /* Libera la memoria ocupada por todos los elmentos de la lista */
  80. void Lista_finalizar(TLista *);
  81. /* Inserta un nuevo elemento en la lista */
  82. void Lista_insertar(TLista *, TElemento);
  83. /* Verifica si la lista está vacía */
  84. int Lista_estaVacia(TLista *);
  85. /* Elimina un elemento de la lista */
  86. void Lista_eliminar(TLista *, TElemento);
  87. /* Obtiene el número de elementos de la lista*/
  88. int Lista_tamanho(TLista *);
  89. /* Verifica si un elemento está en la lista */
  90. int Lista_estaEnLista(TLista *, TElemento);
  91. void Lista_Invertir(TLista *);
  92.  
  93. /*Une conjuntos*/
  94. struct lista conjuntos_Union(TLista *, TLista *);      //<-ON TA BEBE? AQUI TAAAA
  95.  
  96. /* Imprime los elementos de la lista */
  97. void Lista_imprimir(TLista *);
  98.  
  99. #endif  /* LISTAST_H */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement