Red de conocimiento informático - Aprendizaje de código fuente - Estructura de datos, algoritmo, programa: se sabe que una lista enlazada individualmente La con el nodo principal almacena un conjunto de números enteros distintos de cero.

Estructura de datos, algoritmo, programa: se sabe que una lista enlazada individualmente La con el nodo principal almacena un conjunto de números enteros distintos de cero.

La persona de arriba explicó el principio, así que te daré un programa que ya pasó.

Recorre La, coloca valores mayores o iguales a 0 en Lb, y otros en Lc.

#include "stdafx.h"

#include

#include

typedef struct NODE

{

struct NODE *siguiente;

int data;

} T_NODE;

/ / Entrada de almacenamiento de lista enlazada

void InputData(struct NODE * pHead)

{

int count = 10;

T_NODE *p = pHead;

mientras(count-- > 0)

{

p->siguiente = (struct NODE *)malloc(sizeof(struct NODE) ) ;

scanf("%d", &(p->siguiente->datos));

p->siguiente->siguiente = NULL;

p = p->siguiente;

}

p = pHead;

mientras(p->siguiente)

{

printf("%d ", p->siguiente->datos);

p = p->siguiente;

}

printf("\n");

}

int _tmain(int argc, _TCHAR* argv[])

{

//Generar nodo principal de lista enlazada única

struct NODE * pHead_La = (struct NODE *)malloc(sizeof(struct NODE));

pHead_La->data = 0;

pHead_La->next = NULL;

//Ingrese números positivos y negativos

InputData(pHead_La);

struct NODE * pHead_Lb = (struct NODE *)malloc(sizeof(struct NODE));

pHead_Lb->datos = 0;

pHead_Lb->siguiente = NULL;

struct NODE * pHead_Lc = (struct NODE *)malloc(sizeof(struct NODE));

pHead_Lc->datos = 0;

pHead_Lc->siguiente = NULL;

T_NODE *p = pHead_La;

T_NODE *pPostive = pHead_Lb;

T_NODE *pNegativo = pHead_Lc;

mientras(p->siguiente )

{

// Números positivos y 0

si (p->siguiente->datos >= 0)

{

pPostive->next = (struct NODE *)malloc(sizeof(struct NODE));

pPostive->next->data = p->next->data;

p

Postive->siguiente->siguiente = NULL;

pPostive = pPostive->siguiente;

}

else

{

pNegativo->siguiente = (struct NODE *)malloc(sizeof(struct NODE));

pNegativo->siguiente->datos = p->siguiente->datos;

pNegativo->siguiente->siguiente = NULL;

pNegativo = pNegativo->siguiente;

}

p = p->siguiente;

}

pPostive = pHead_Lb;

mientras(pPostive->siguiente)

{

printf( "%d ", pPostive->siguiente->datos);

pPostive = pPostive->siguiente;

}

printf("\n") ;

pNegativo = pHead_Lc;

mientras(pNegativo->siguiente)

{

printf("%d ", pNegativo- >siguiente->datos);

pNegativo = pNegativo->siguiente;

}

printf("\n");

devuelve 0;

}