A POINTER LOST THE WAY(Marked as *)

I AM USING C++ with XCODE.

#include <iostream>
#include <stdlib.h>
#include <string.h>
using namespace std;

struct custom{
custom* pLink;
custom* pToFl;
string name;

};

typedef struct portNode{
int numberOfCus = 0;
string flightName;
custom headerNode;
portNode* pLink;
}flight;

struct airport{
int numberOfPort = 0;
flight headerNode;
};

airport* createAirport(){
airport* pReturn = NULL;

pReturn = (airport*)malloc(sizeof(airport));

if(pReturn != NULL){
memset(pReturn, 0, sizeof(airport));
}
else{
cout << "메모리 할당 실패" << endl;
return NULL;
}
return pReturn;
}

void addFlight(airport* pList, string newFlightName){
flight* pNewFlight = NULL;
flight* pPreNode = NULL;

if(pList != NULL){
pPreNode = &(pList->headerNode);
while(pPreNode->flightName != newFlightName){
if(pPreNode -> flightName != newFlightName && pPreNode -> pLink == NULL){
pNewFlight = new flight;
pNewFlight -> flightName = newFlightName;
pNewFlight -> pLink = NULL;

pNewFlight -> pLink = pPreNode -> pLink;
pPreNode -> pLink = pNewFlight;
}
pPreNode = pPreNode->pLink;
}
pList->numberOfPort++;
}
}

void addCustomer(airport* pList, string newFlightName, string newName){
custom* pNewCustom = NULL;
custom* pPreNode = NULL;
flight* pNewFlight = NULL;

if(pList != NULL){
pNewCustom = new custom;
if(pNewCustom != NULL){
pNewCustom -> pLink = pNewCustom;
pNewCustom -> name = newName;

pNewFlight = &(pList->headerNode);

while(pNewFlight->flightName != newFlightName){
pNewFlight = pNewFlight -> pLink;
}

pPreNode = &(pNewFlight->headerNode);


pNewCustom -> pToFl = pPreNode;
pNewCustom -> pLink = pPreNode -> pLink;
pPreNode -> pLink = pNewCustom;

}



Last edited on
Usually the end of a list is signaled by current_node == nullptr, not by current_node->next_node == current_node.
@helios
THIS IS BECAUE IT"S DOUBLE LINKED LIST.
I TRIED WITH SINGLE LIST BUT IT HAS SAME ERROR.
I AM MAKING 2D LINKED LIST.
Topic archived. No new replies allowed.