PROGRAMACION IV

BACH. TC. N°16

6°B

LUIS ALBERTO JAIME PARRA

 

 

#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
#include <dos.h>
int contador,x;
char datos[20];
struct lista
{
char info[20];
struct lista *liga;
};

struct lista *inicio, *final, *nuevo, *temporal, *temp3, *temp1;

void cre(char *dts);
void rec(struct lista *p);
void elim();
void main ()
{textcolor(RED);
int opc; contador=0; char k;

do{

clrscr();
printf("Elige una Opcion:\n ");
printf("\n ");
printf("1.-Crear o agregar un elemento a la lista.\n ");
printf("2.-Recorrer lista.\n ");
printf("3.-Eliminar el ultimo elemento.\n ");
printf("4.-Salir.\n ");


opc=getche();delay(50);
switch(opc){

case '1': k='s';
do
{clrscr();
contador=contador+1;
printf("introduce un nombre: ");
scanf("%s",&dts);
printf("\n\n");
cre(dts);
printf("Quieres meter mas datos? ('S' o 'N'): ");
k=getche();
}
while ((k!='n')&&(k!='N'));
getch(); break;


case '2':clrscr();
printf("Nombre:\n");
rec(inicio);
getch(); break;

case '3':clrscr();
printf("Eliminando...\n\n");
elim(); delay(1500);
printf("Eliminado Satisfactoriamente...");
getch(); break;

}}while(opc!='4');

}

void rec(struct lista *p)
{if (p!=NULL)
{printf("%s\n",p->informacion);
rec (p->liga);} }

void cre(char *dts)
{
if (contador==1)
{inicio=(struct lista *)malloc(sizeof(struct lista));
strcpy(inicio->informacion,dts);
inicio->liga=NULL;
final=inicio;}

if (contador>1)
{temp3=inicio;
while (temp3->liga!=NULL)
temp3=temp3->liga;
temporal=(struct lista *)malloc(sizeof(struct lista));
strcpy(temporal->informacion,dts);
temporal->liga=NULL;
temp3->liga=temporal;}}

void elim()
{
struct lista *t,*q;
if (inicio->liga==NULL)
{contador=0;
free (inicio);
for (x=0;x<=19;x++)
inicio->informacion[x]=' ';}
else
{
q=inicio;
while (q->liga!=NULL)
{t=q; q=q->liga;
}t->liga=NULL;
free(q);
}
}

CONCLUCIONES: SE ME TRAVO..

Hosted by www.Geocities.ws

1