I'm having the worst time trying to add a node into a linked list. I can't even get the node in. My instructor said this would work, but I think he must have read it over too quickly. The list is supposed to be in ascending order of Zip codes.
Code:
struct SListNode{
char City[41];
char State[3];
char Zip[6];
double Longitude;
double Latitude;
long Population;
struct SListNode *Next;
struct SListNode *Prev;
};
void vAddListNode (struct SListHeader *psList, struct SListNode *psNode)
{
struct SListNode *psNext=NULL;
int comp;
psList->iNodeCount = psList->iNodeCount+1;
psNext = psList->psHead;
comp = strcmp(psNode->Zip, psNext->Zip);
while (comp > 0)
{
psNode->Next = psNext;
psNode->Prev = psNext->Prev;
psNode->Next->Prev = psNext;
psNode->Prev->Next = psNext;
psNext = psNode->Next;
printf("City5: %s", psNext->City);
printf("City5: %s", psNode->City);
comp = strcmp(psNode->Zip, psNext->Zip);
}
}