Sie sind auf Seite 1von 8

#include<conio.h> #include<stdio.h> #include<ctype.h> #include<stdlib.h> #include<string.

h> // DEFINICION DE LAS ESTRUCTURAS struct lista1; struct lista2; struct lista3; // ESTRUCTURAS typedef struct lista1{ int info; lista1 *sig; lista2 *sig_ptr2; }; typedef struct lista2{ int info; lista2 *sig; lista3 *sig_l3; }; typedef struct lista3{ int info; lista3 *sig; }; // DEFINICION DE PUNTEROS AUXILIARES struct lista1 *ptr1=NULL,*a,*b; struct lista2 *ptr2=NULL,*c,*d; struct lista3 *ptr3=NULL,*e,*f; //DEFINICION DE FUNCIONES void menu_principal(); void insertar_lista1(); void mostrar_lista1(); void insertar_lista3(); void mostrar_lista3(); void enlazar(); int buscar_lista1(int numero); int buscar_lista3(int numero); void mostrar_enlace(); void eliminar(); // VARIABLES GLOBALES int s;

main() {//inicia funcion int opc,salir; do{ system("cls"); salir=0; menu_principal(); printf("\n"); printf("Ingrese Opcion : "); scanf("%d", & opc); switch(opc) { case 1: insertar_lista1(); getch(); break; case 2: if(ptr1!= NULL) { mostrar_lista1(); } else { printf("\n:::LISTA 1 VACIA:::"); } getch(); break; case 3: if(ptr1!=NULL && ptr3!= NULL) { enlazar(); } else { printf("ASEGURESE DE INSERTAR LISTA1 Y LISTA3"); } getch(); break; case 4: if(ptr1!=NULL && ptr3!= NULL) { mostrar_enlace(); } else { printf("ASEGURESE DE INSERTAR LISTA1 Y LISTA3"); } getch(); break; case 5: insertar_lista3(); getch();

break; case 6: if(ptr3!= NULL) { mostrar_lista3(); } else { printf("\n:::LISTA 3 VACIA:::"); } getch(); break; case 7: if(ptr1!=NULL) { eliminar(); } else { printf("\n:::LISTA 1 VACIA:::"); } getch(); break; case 8: salir=1; printf(":::UD DECIDIO SALIR DEL PROGRAMA :::"); getch(); break; default: break; } }//cierre del do while(salir!=1); return 0; }//fin funcion // FUNCIONES void menu_principal() {//INCIA printf(":::MENU EJERCICIO::: \n"); printf("1. INSERTAR LISTA 1 \n"); printf("2. MOSTRAR LISTA 1 \n"); printf("3. INSERTAR LISTA 2 \n"); printf("4. MOSTRAR LISTA 2 \n"); printf("5. INGRESAR LISTA 3 \n"); printf("6. MOSTRAR LISTA 3 \n"); printf("7. ELIMINAR LISTA 1 \n"); printf("8. SALIR \n"); }//FIN void insertar_lista1() {//inicia funcion int num;

printf("Ingrese Numero : "); scanf("%d", &num ); a= (struct lista1 *)malloc(sizeof (struct lista1)); a->sig_ptr2=NULL; a->info=num; if(ptr1==NULL) { ptr1=a; a->sig=NULL; } else { b=ptr1; while(b->sig != NULL) { b=b->sig; } b->sig=a; a->sig=NULL; } printf("\n NUMERO INSERTADO EXITOSAMENTE"); }// fin funcion void mostrar_lista1() {//inicia funcion a=ptr1; while(a!=NULL) { printf("%d \n", a->info); a=a->sig; } }//fin funcion void insertar_lista3() {//inicia int num; printf("Ingrese un Numero : "); scanf("%d", & num); e= (struct lista3 *)malloc(sizeof (struct lista3)); e->info = num; if(ptr3==NULL) { ptr3=e; e->sig=NULL; } else {

f=ptr3; while(f->sig != NULL) { f=f->sig; } f->sig=e; e->sig=NULL; } printf("\n NUMERO INSERTADO EXITOSAMENTE"); }//fin void mostrar_lista3() {//inicia funcion e=ptr3; while(e!=NULL) { printf("%d \n", e->info); e=e->sig; } }//FIN int buscar_lista1(int numero) {//INICIA if(a==NULL) { return s; } else { if(a->info == numero) { s=1; b=a; a=NULL; } else { a=a->sig; } return buscar_lista1(numero); } }//FIN int buscar_lista3(int numero) {//INICIA if(e==NULL) { return s; } else

{ if(e->info == numero) { s=1; f=e; e=NULL; } else { e=e->sig; } return buscar_lista3(numero); } }//FIN

void enlazar() { int num,sw,sw2; printf("Ingrese info de la lista1 : "); scanf("%d", &num); s=0; a=ptr1; sw=buscar_lista1(num); printf("Ingrese info de la lista3 : "); scanf("%d", &num); s=0; e=ptr3; sw2=buscar_lista3(num); if(sw==1 && sw2==1) { printf("Ingrese info lista2 : "); scanf("%d", &num); c= (struct lista2 *)malloc(sizeof (struct lista2)); c->info = num; if(b->sig_ptr2 ==NULL) { b->sig_ptr2=c; c->sig=NULL; } else { c->sig= b->sig_ptr2; b->sig_ptr2=c; } //ENLACE c->sig_l3 = f;

printf("ENLACE REALIZADO SATISFACTORIAMENTE"); } else { printf("Alguna informacion no se encontro"); } }//FIN void mostrar_enlace() {//INCIIA int num,sw; printf("Ingrese info de la lista1 : "); scanf("%d", &num); s=0; a=ptr1; sw=buscar_lista1(num); if(b->sig_ptr2 != NULL) { c=b->sig_ptr2; while(c!=NULL) { e=c->sig_l3; printf("Enlace %d con %d \n", c->info, e->info ); c=c->sig; getch(); } } else { printf("Esta informacion no ha sido enlazada "); } }//FIN void eliminar() {//INICIA int num,sw; printf("Ingrese numero a eliminar : "); scanf("%d", & num); a=ptr1; s=0; sw=buscar_lista1(num); if(sw==0) { printf("No existe esa informacion"); } else

{ if(b==ptr1) { free(ptr1); } else { a=ptr1; while(a->sig != b) { a=a->sig; } a->sig = b->sig; free(b); } printf("Informacion eliminada satisfactoriamente"); } }//fin funcion

Das könnte Ihnen auch gefallen