Estructura de datos Tabla única relacionada Crear Imprimir Eliminar Insertar consulta Informe del experimento
#include lt;iostreamgt;
usando el espacio de nombres std;
typedef struct node
{
datos de caracteres;
nodo de estructura *siguiente;
}enlace
enlace * get(enlace *l, int i)
{
enlace *p; int j=0
p=l
while((jlt;i) amp;amp; (p-gt.next!=NULL))
{p=p-gt;next;j;}
if(j==i)
return p;
else
return NULL;
}
enlace * ins (enlace *l, char ch, int i )
{ enlace *p, *s;
p=get(l, i-1
if(p==NULL) p>
coutlt;lt; "Error de entrada"lt;lt; endl;
else
{
s=(enlace *)malloc(sizeof(enlace)
s-gt; datos=ch;
s-gt; siguiente=p-gt; siguiente
p-gt; ;
}
return l;
}
enlace * buscar(enlace *l, char ch)
{
enlace *p; int i=0; int j=0;
p=l
mientras(p!=NULL)
{ i;
if(p-gt; datos!=ch)
p=p-gt; siguiente
else {coutlt; ; "Los datos que buscas están en la posición "lt;lt;i-1lt;lt; "position." ;
}
}
if(j!=1)
coutlt;lt; "Los datos que estás buscando son no en línea Mesa de sexo.
" lt; lt; endl;
return l;
}
enlace * del(enlace *l, int i)
{
enlace *p, *s;
p=get(l, i-1
if(p==NULL)
coutlt;lt; "Error de entrada"lt;lt;endl;
else
{
s=p-gt;next;
p-gt; siguiente=s-gt;
gratis(s);
}
devolver l; p>
p>
}
enlace * agregar(enlace *l)
{
enlace *p, *s; p>
coutlt;lt; "Ingrese una sola cadena de datos de caracteres, terminada en *! " lt; lt; endl;
char ch;
enlace *HEAD;
enlace *R, *P, *L;
HEAD=(enlace *)malloc(sizeof(enlace));
HEAD-gt; next=NULL
R=HEAD; ();
ch=getchar();
ch=getchar();
while(ch!='*')
{
P=(enlace *)malloc(sizeof(enlace));
P-gt; p-gt; >
R-gt; siguiente=P; R=R-gt;
getchar(); > }
L=HEAD;
coutlt;lt; "La tabla lineal de entrada actual es: "lt;lt;endl;
P=L; P =P-gt;siguiente;
if(L!=NULL)
hacer
{coutlt;lt;P-gt;datalt;lt; " ";
P =P-gt; siguiente;
}mientras(P!=NULL
endl; >
p=l;
mientras(p-gt; siguiente!=NULL)
p=p-gt
s=; L ;
p-gt; siguiente=s-gt;
p=l;
enlace * print(enlace *l)
{ int i, k
char ch
enlace * p, * q ;
coutlt;lt; "La tabla lineal actual es: "lt;lt;endl;
p=l;p=p-gt;next;
if(l!
hacer
{coutlt;lt;p-gt;d
atalt;lt;" ";
p=p-gt;next;
} while(p!=NULL);
coutlt;lt;endl ;
coutlt;lt; "Seleccione la acción que desea realizar:";
coutlt;lt;" 1. Inserte ";
coutlt; lt; " 2. Buscar";
coutlt; lt; " 3. Eliminar";
coutlt; ;lt; "0, salir";
coutlt;lt; endl
cingt;gt;k;
if(k==1)
{
coutlt;lt; "Por favor ingrese el valor de los datos que desea insertar:"
cingt;gt;ch;
coutlt;lt; "Ingrese la posición que desea insertar:";
cingt;gt;i;
p=ins(l,ch,i);
q=print(l);
}
else if(k==2)
{
coutlt ;lt; "Ingrese el valor de los datos que está buscando:";
cingt;gt;ch;
p=find( l,ch );
q=print(l);
}
else if(k==3)
{
coutlt;lt; "Ingrese la ubicación de los datos que desea eliminar:";
cingt;gt;i;
p=del(l , i);
q=print(l);
}
si no (k==4)
{ p =add(l);
q=print(l);
}
}
else if(k== 0)
;
else
{coutlt;lt; "¡Error de entrada!" imprimir(l); }
devolver l;
}
int main()
{
coutlt;lt; " ¡Ingrese una sola cadena de datos de caracteres que terminen en *! " lt; lt; endl;
char ch;
//enlace *head;
enlace *r, *p, *q, *l;
l=(enlace *)malloc(sizeof(enlace));
l-gt; siguiente=NULL
r=l; ;
ch=getchar();
// getchar();
while(ch!='*')
{
p=(enlace *)malloc(tamañode(enlace)
);
p-gt; .data=ch; siguiente=NULL
r-gt; /p>
ch=getchar();
// getchar();
}
//l=cabeza;
q= print(l);
return 0;
}
2.
2.
#include lt; stdio.hgt;
#include lt; malloc.hgt
#define N 8
estructura de tipo nodo
{int datos;
estructura nodo *siguiente;
}nodo
nodo * creal()
{
nodo *p, *s, *h;
int j =1, x
p=s=h=(nodo; *)malloc(sizeof(node));
h-gt; next=NULL;
printf("ingrese los datos para crear la lista, finalice con -1 o d números\n", N);
while(x!=-1amp;amp;jlt;=N)
{
printf("número d : ", j);
scanf("d", amp; x);
s=(nodo* )malloc(tamañode(nodo));
s-gt; datos=x;
if(h-gt; siguiente==NULL)
siguiente=s; otro
p-gt;siguiente=s;
p=s;
j; > p-gt; siguiente=NULL;
return h;
}
int acceso(nodo *h, int i)
{
nodo *p; int j=1;
p=h-gt; siguiente;
if(p-gt; data==i)
descanso
p=p-gt; ;
}
if(p-gt;data==i)
romper;
p=h-gt;siguiente ;
while(p!
if(p !=NULL)
{
printf("busca el número en la posición: d\n", j);
return(p-gt; datos);
}
else
{ p>
p>
printf("¡No puedo encontrar el número en la lista!\n");
return -
1;
}
}
}
}
}
nulo insertsl(nodo *h, int i)
{
nodo *p, *t
int j=1; p> p=h-gt; siguiente;;
while(p-gt; siguiente!=NULL)
{
p=p-gt; siguiente;
j ;
}
}
t=(nodo*)malloc( tamaño de(nodo)); p>
t-gt; datos=i;
t-gt; siguiente=p-gt;
p-gt; >
printf("insertar éxito en la posición d\n", j 1
}
void deletesl(nodo *h, int i)
{
nodo *p, *s, *q;
int j=1;
p=h; p> while( p-gt; siguiente! =NULL)
p> {
q=p-gt;
if(q-gt; ; datos== i)
romper
p=p-gt; >
if(p-gt; next==NULL)
{
printf("No puedo encontrar el número que desea eliminar.\n"); /p>
retorno;
}
más
{
s=p-gt; >
p-gt; next=s-gt; siguiente;
free(s);
printf("eliminar correctamente en la posición d\n", j 1)
}
}
void print(nodo *h)
{
printf( "/nimprime todos los datos de la lista: ");
nodo *s;
s=h-gt;
if(s!
{
while(s!=NULL)
{
printf(" d ", s-gt; datos);
s=s-gt; siguiente
}
}
}
más
printf("¡la lista está vacía!d");
printf("\n");
}
int main();
{
nodo *p;
int a
p=createsl(); ("/nnecesitas encontrar el número:\
n");
scanf("d", amp; a);
access(p, a);
printf("/npor favor ingrese el número que desea insertar:\n");
scanf("d", amp.a);
insertsl(p, a);
printf("/ningrese el número que desea eliminar:\n");
scanf("d", amp; a
eliminasl(p, a);
imprimir(p);
devolver 0;