Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have the following C program, which shows the union and complement of two sets #include #include struct nodo { int num; struct nodo *sig;

I have the following C program, which shows the union and complement of two sets
#include  #include  struct nodo { int num; struct nodo *sig; }; struct nodo *ConjA, *ConjB, *ConjResp, *Universo, *Comple_Conj; struct nodo *CreaNodo(int num) { struct nodo *new = (struct nodo*)malloc(sizeof(struct nodo)); new->num = num; new->sig = NULL; return new; } void inicializa(void) { ConjA = ConjB = ConjResp = Universo = Comple_Conj = NULL; } void PonerEnListaA(struct nodo *new) { if ( !ConjA ) ConjA = new; else { new->sig = ConjA; ConjA = new; } } void PonerEnListaB(struct nodo *new) { if ( !ConjB ) ConjB = new; else { new->sig = ConjB; ConjB = new; } } void CreaConjunto(int tam, int V[], char Conj) { int x = 0; struct nodo *new=NULL; for (x = 0; xnum); aux = aux->sig; } printf(" "); } int Existe(int num) { struct nodo *aux = ConjResp; while(aux) { if (num == aux->num) return 1; aux = aux->sig; } return 0; } void Union(void) { struct nodo *aux=NULL, *new = NULL; aux = ConjA; while(aux) // COPIAMOS EL CONJUNTO A EN RESP { new = CreaNodo(aux->num); if ( !ConjResp ) ConjResp = new; else { new->sig = ConjResp; ConjResp = new; } aux = aux->sig; } aux = ConjB; while(aux) // COPIAMOS DE CONJB LOS QUE NO ESTAN REPETIDOS { if ( !Existe(aux->num) ) { new = CreaNodo(aux->num); if ( !ConjResp ) ConjResp = new; else { new->sig = ConjResp; ConjResp = new; } } aux = aux->sig; } } int RevisaComplemento(int num, struct nodo *aux) { while(aux) { if (num == aux->num) return 1; aux = aux->sig; } return 0; } void Complemento(struct nodo *Conjunto) { struct nodo *U_aux = Universo, *new=NULL; while ( U_aux ) { if ( !RevisaComplemento(U_aux->num, Conjunto) ) { new = CreaNodo(U_aux->num); if ( !ConjResp ) ConjResp = new; else { new->sig = ConjResp; ConjResp = new; } } U_aux = U_aux->sig; } } void inicio() { int LA[] = {1, 2, 3, 4, 6}; int LB[] = {3, 5, 6, 7, 9}; CreaConjunto(5, LA, 'A'); CreaConjunto(5, LB, 'B'); printf("El conjunto A es: "); Muestra(ConjA); printf("El conjunto B es: "); Muestra(ConjB); Union(); Universo = ConjResp; printf("La unin es: "); Muestra(Universo); ConjResp = NULL; Complemento(ConjA); Comple_Conj = ConjResp; printf("El complemento de A' es: "); Muestra(Comple_Conj); } int main(char **a, int b) { inicializa(); inicio(); }

I need to also do and show the intersection and difference of the same sets used previously (in union and complement)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals Design And Implementation

Authors: KROENKE DAVID M.

1st Edition

8120322258, 978-8120322257

More Books

Students also viewed these Databases questions

Question

What is the cerebrum?

Answered: 1 week ago