¿Crear una lista enlazada individualmente con el nodo principal, insertar un nuevo nodo antes del nodo i-ésimo en la lista enlazada individualmente y eliminar el nodo i-ésimo?
Nota: Los datos del nodo en el código fuente solo pueden tener un carácter,
#include lt; stdio.hgt;
#include stdlib. hgt ;
typedef char Tipo de datos;
typedef struct nodo
{
int datos;
struct nodo * siguiente;
}ListNode;
typedef ListNode *LinkList;
LinkList CreatListRH(void)
{
Tipo de datos ch;
encabezado de lista de enlaces;
nodo de lista *s, *r
encabezado = (nodo de lista *)malloc(tamaño de (nodo de lista));
r=head;
printf("Ingrese datos para cada nodo de la tabla de cadena:\n");
while((ch=getchar ( ))! = '\n')
{
s=(ListNode *)malloc(sizeof(ListNode));
s-gt; datos =ch;
r-gt; siguiente=s;
r=s;
}
r-gt; = NULL;
return head;
}
LinkList GetNode(LinkList head, int i)
{
if(i lt; 0)
Devuelve NULL;
else
while(i)
{
cabeza = cabeza-gt; siguiente;
i--;
}
Volver al encabezado
}
int InserList(encabezado de lista de enlaces, tipo de datos x, int i)
{
ListNode *p, *s;
p=GetNode (head , i-1);
if(p==NULL)
{
printf("nodo dth no encontrado\n", i- 1) ;
devuelve 0
}
s=(ListNode *)malloc(sizeof(ListNode)); -gt ;datos=x;
s-gt;next=p-gt;siguiente;
p-gt;next=s;
devuelve 1 ;
}
int DeleteList(encabezado de LinkList, int i)
{
ListNode*p, *r;
p=GetNode(cabeza, i-1
if);
(p==NULL||p-gt; next==NULL)
{
printf("nodo dth no encontrado\n", i-1);
devolver 0;
}
r=p-gt;siguiente;
p-gt.next=r-gt;siguiente;
gratis(r);
devuelve 1;
}
¿void printList(encabezado de LinkList)?
{
printf("Atravesando la lista de enlaces de salida para \n");?
while(head-gt; next ! = NULL)
{
head = head-gt;
printf( "c ", cabeza-gt; datos);
}
printf("\n");?
}
void freeList(encabezado de LinkList)
{
LinkList p;
while(head != NULL)
{
p = cabeza;
cabeza = cabeza-gt; siguiente;
gratis(p);
int main()
{
Tipo de datos x;
int i
Lista de enlaces p = CreatListRH ();
printList(p);
printf("Ingrese el valor y la posición a insertar\n"); amp;
printList(p);?
}
printf("Ingrese la posición del nodo a eliminar\n");
scanf("d",&i);
if(DeleteList(p,i))
{
printf("Eliminación exitosa, " );
printList(p);?
}
freeList(p); 0;
}