You are on page 1of 5

UNIVERSIDAD NACIONAL MAYOR DE SAN MARCOS

(Universidad del Perú, DECANA DE AMÉRICA)

FACULTAD DE INGENIERÍA DE SISTEMAS E INFORMÁTICA

ESCUELA PROFESIONAL DE INGENIERÍA DE SOFTWARE

Estructura de Datos: Práctica Dirigida 03

Código: Apellidos y nombres:


● 21200259: Saavedra Monterrey, Max Bruno

Docente:
Pro Concepción Luzmila
LIMA-PERÚ
2022

Fecha de Entrega: Semana 4


Implementación del Código en C++

# include <iostream>
# include <stdio.h>
# include <stdlib.h>
# include <conio.h>
# include <string.h >
# include <windows.h>

using namespace std;

struct nodo
{
char apellidos[30];
char nombres [30];
char fono[7];
char domicilio [30];
struct nodo *next;
};

typedef struct nodo *LISTAPTR;


LISTAPTR GETNODO( );
void LISTA_CREATE(LISTAPTR I);
LISTAPTR(getnodo ( ));
void create( );

void display ( );
int menu ( );
void remove ( );

// variables globales
LISTAPTR nodo_inicial, lista =NULL;

int main()
{
int k;
for(; ;)
{
k =menu ( );
switch (k)
{
case 1 : create ( );
break;
case 2 : display ( );
break;
case 3 : remove ( );
break;
case 4 : exit (0);
break;
}
}
}
int menu()
{
int ch;
int x, y;
system("cls");
//clrscr();
cout<<"\t1.Creacion " <<endl;
cout<<" \t2.Listado " <<endl;
cout<<"\t3. Remocion "<<endl;
cout<<"\t4.Fin "<<endl;
cout<<"\n\tIngrese una opcion(1-4):";
do{
cin>>ch;
}while(ch <1 && ch>4);
return ch;
}

LISTAPTR getnodo()// C
{
LISTAPTR p;
p=(LISTAPTR)malloc(sizeof(struct nodo));
return p;
}

void remove()
{
LISTAPTR q, p;
char s[30];
system("cls");
//clrscr();
gets(s);
cout<<"Ingeres apellidos: ";
gets(s);
q=NULL;
p=nodo_inicial;
while(p!=NULL)
{
if(strcmp(p->apellidos,s)==0)
{
free(nodo_inicial);
nodo_inicial =p;
lista=p;
}
else
{
free(q->next);
q->next =p;
if(p==NULL)
{
lista=q;
}
else{
q=p;
p=p->next;
}
}
}
}

void display()
{
register int i=0;
LISTAPTR p;
char s[30];
system("cls");
//clrscr();
p=nodo_inicial;
while(p!=NULL) {
cout<<"\nREGISTRO "<<endl;
cout<<" apellidos : "<<p->apellidos <<endl;
cout<< "nombres : "<<p->nombres<<endl;
p=p->next;
cout<<"Presione cualquier tecla";
getch();
}
}
void LISTA_CREATE(LISTAPTR I)
{
if(lista==NULL)
nodo_inicial =I;
else
{
lista->next = I;
lista = I;
I->next =NULL;
}
}
void create()
{
LISTAPTR i;
int n,j;
char s[80];
system("cls");
//clrscr();
cout<<"ingrese numero de datos :";
cin>>n;
gets(s);
for( j=0;j<n;j++)
{
i=getnodo();
if(i==NULL) {
cout<<" fuera de memoria" <<endl;
exit(1);
}
else{
cout<< "apellidos :";
gets(i->apellidos);
cout<< "nombres : ";
gets(i->nombres);
cout<<"fono :";
gets(i->fono);
cout<<" domicilio :";
gets(i->domicilio);
LISTA_CREATE(i);
}
}
}

You might also like