Tags » Problem

UVa Problem Solution: 924 - Spreading the News

Link: http://uva.onlinejudge.org/external/9/924.pdf
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>

#define TOTAL_NODE 2550
#define INVALID 2147483647


typedef struct mNode{
    int iNodeName;
    int iEdgeWeight;
    bool rVisited;
    int rCost;
    struct mNode *iNextNode;
    struct mNode *rPreviousNode;
    struct mNode *bBaseAddress;

}Node;

void Enqueue(Node *,Node *);
bool Dequeue(Node **,Node **);
void InitializeQueue();

Node *AllNodeList;
void PutInNodeList(int FromNode, int ToNode, int EdgeWeight);
Node * GetNodeBaseAddress(int NodeName);
int GetNodeDegree(int NodeName);
int NodeIndexHead = 0;
void SetupNode(Node *mNodeAddress, int mNodeName, int mEdgeWeight, int mCost, Node *mNodeBaseAddress);
int TotalNodeInGraph(void);
int TotalEdgeInGraph(void);
void UpdateNodeValues(Node *mNodeAddress, int mEdgeWeight, Node *mNextNode, int mCost, Node *mPreviousNode, int mVisited);
void ClearGRAPH();

int BFS(int startNode,int endNode,int startCost);
void ClearBFSResult();

int mMax;
int mDay;

int main()
{
    freopen("input.txt","r",stdin);
    int mEmployeeCount,mQueryCount,friendCount,i,j,tmp;
    scanf("%d",&mEmployeeCount);
    for(i=0;i<mEmployeeCount;i++){
        scanf("%d",&friendCount);
        for(j=0;j<friendCount;j++){
            scanf("%d",&tmp);
            PutInNodeList(i,tmp,1);

        }

    }
    scanf("%d",&mQueryCount);
    for(i=0;i<mQueryCount;i++){
        scanf("%d",&tmp);
        BFS(tmp,-1,0);
        if(mDay!= 0){
            printf("%d %d\n",mMax,mDay);
        }else{
            printf("0\n");
        }
        ClearBFSResult();
    }

    return 0;
}

typedef struct smQueue{
    Node *smX;
    Node *smY;
    struct smQueue *next;
}smNode;


smNode *smFirstNode, *smLastNode, *tempNode;
bool firstTime = true;

void Enqueue(Node *valX, Node *valY){
    smNode *nde = malloc(1 * sizeof(smNode));
    if(firstTime){
        firstTime = false;
        smFirstNode = nde;
        smLastNode = nde;
        smLastNode->smX = valX;
        smLastNode->smY = valY;
        smLastNode->next = NULL;
        return;
    }
    smLastNode->next = nde;
    smLastNode = nde;
    smLastNode->smX = valX;
    smLastNode->smY = valY;
    smLastNode->next = NULL;

}


bool Dequeue(Node **smValueX, Node **smValueY){

    if(smFirstNode!=NULL){
        *smValueX = smFirstNode->smX;
        *smValueY = smFirstNode->smY;
        tempNode = smFirstNode->next;
        free(smFirstNode);
        smFirstNode = tempNode;
        if(smFirstNode==NULL){
            firstTime = true;
        }
        return true;
    }
    return false;
}

void InitializeQueue(){
    Node *a,*b;
    while(Dequeue(&a,&b));
}

void PutInNodeList(int FromNode, int ToNode, int EdgeWeight){
    Node *tempNode = GetNodeBaseAddress(FromNode);

    if(tempNode != NULL){
        while(tempNode->iNextNode != NULL){
            tempNode = tempNode->iNextNode;
        }
        Node *tmp = (Node*) malloc(1 * sizeof(Node));

        Node *baseAddress = GetNodeBaseAddress(ToNode);
        if(baseAddress == NULL){
            baseAddress = (Node*) malloc(1 * sizeof(Node));
            SetupNode(baseAddress,ToNode,INVALID,INVALID,baseAddress);
            AllNodeList = baseAddress;
        }

        SetupNode(tmp,ToNode,EdgeWeight,INVALID,baseAddress);
        tempNode->iNextNode = tmp;

    }else{
        Node *tmp1 = (Node*) malloc(1 * sizeof(Node));
        SetupNode(tmp1,FromNode,INVALID,INVALID,tmp1);
        AllNodeList = tmp1;
        int tmpNodeHead = NodeIndexHead-1;

        Node *baseAddress = GetNodeBaseAddress(ToNode);
        if(baseAddress == NULL){
            baseAddress = (Node*) malloc(1 * sizeof(Node));
            SetupNode(baseAddress,ToNode,INVALID,INVALID,baseAddress);
            AllNodeList = baseAddress;
        }

        Node *tmp2 = (Node*) malloc(1 * sizeof(Node));
        SetupNode(tmp2,ToNode,EdgeWeight,INVALID,baseAddress);
        AllNodeList -> iNextNode = tmp2;
    }
}

void SetupNode(Node *mNodeAddress, int mNodeName, int mEdgeWeight, int mCost, Node *mNodeBaseAddress){
    mNodeAddress->iEdgeWeight = mEdgeWeight;
    mNodeAddress->iNextNode = NULL;
    mNodeAddress->iNodeName = mNodeName;
    mNodeAddress->rCost = mCost;
    mNodeAddress->rPreviousNode = NULL;
    mNodeAddress->rVisited = false;
    mNodeAddress->bBaseAddress = mNodeBaseAddress;
}

void UpdateNodeValues(Node *mNodeAddress,
                      int mEdgeWeight,
                      Node *mNextNode,
                      int mCost,
                      Node *mPreviousNode,
                      int mVisited){
    if(mEdgeWeight!=INVALID){
        mNodeAddress->iEdgeWeight=mEdgeWeight;
    }

    if(mNextNode != NULL){
        mNodeAddress->iNextNode = mNextNode;
    }

    if(mCost != INVALID){
        mNodeAddress->rCost = mCost;
    }

    if(mPreviousNode!=NULL){
        mNodeAddress->rPreviousNode=mPreviousNode;
    }
    if(mVisited != 0){
        if(mVisited>0){
            mNodeAddress->rVisited = true;
        }else{
            mNodeAddress->rVisited = false;
        }
    }

}


Node * GetNodeBaseAddress(int NodeName){
    int i;
    for(i=0;i<NodeIndexHead;i++){
        if(AllNodeList[i]->iNodeName == NodeName){
            return AllNodeList[i];
        }
    }
    return NULL;
}

int GetNodeDegree(int NodeName){
    Node* tmp = GetNodeBaseAddress(NodeName);
    int i=0;
    if(tmp!=NULL){
        tmp = tmp->iNextNode;
    }
    while(tmp!=NULL){
        i++;
        tmp=tmp->iNextNode;
    }
    return i;
}

int TotalNodeInGraph(){
    return NodeIndexHead;
}

int TotalEdgeInGraph(){
    return INVALID;
}

void ClearGRAPH(){
    int i;
    for(i=0;i<NodeIndexHead;i++){
        AllNodeList[i]=NULL;
    }
    NodeIndexHead = 0;
}

int BFS(int startNode,int endNode,int startCost){

    Node *bfsTmpNode, *bfsTmpParentNode, *bfsGarbageNode,*bfsListTraversal;
    memset(mMax,0, sizeof(mMax));
    mDay = 0;
    int tmpMax=0;
    bfsTmpNode = GetNodeBaseAddress(startNode);
    if(bfsTmpNode==NULL){
        return 0;
    }
    InitializeQueue();
    bfsTmpNode->rVisited = true;
    bfsTmpNode->rCost = startCost;
    bfsTmpNode->rPreviousNode = NULL;
    Enqueue(bfsTmpNode,NULL);

    while(Dequeue(&bfsTmpParentNode,&bfsGarbageNode)){
        bfsListTraversal = bfsTmpParentNode;

        while(1){
            bfsListTraversal = bfsListTraversal->iNextNode;
            if(bfsListTraversal==NULL) break;

            bfsTmpNode = bfsListTraversal->bBaseAddress;
            if(bfsTmpNode->rVisited) continue;
            bfsTmpNode->rVisited = true;
            bfsTmpNode->rCost = bfsTmpParentNode->rCost + 1;
            bfsTmpNode->rPreviousNode = bfsTmpParentNode;

            mMax++;
            if(mMax>tmpMax){
                mDay = bfsTmpNode->rCost;
                tmpMax = mMax;
            }

            Enqueue(bfsTmpNode,NULL);
        }
    }

    return 0;
}


void ClearBFSResult(){
    int i;
    for(i=0;i<NodeIndexHead;i++){
        AllNodeList[i]->rCost = INVALID;
        AllNodeList[i]->rPreviousNode = NULL;
        AllNodeList[i]->rVisited = false;
    }

} 16 more words
UVa

How me being a woman turned out to be an issue

As I mentioned before, I had to move within New York for three times in only one month. You wonder why? Well, the first two times were somehow planned. 943 more words

New York City

Our Daily Gem

 

“Don’t  focus on your problem.  Focus on your dream.” – Bo Sanchez

#feelfreetoshare

Followmo: brodmofernandez.com

Wisdom

WATCH: Check Out This dog's Problem Solving Skills

Everyone has challenges. This dog has an amazing stick which he has to get across a bridge. Check out what he does! –Jax

Shows

I wish I could live my life without paranoia.

 

Be positive and have sweetdreams
~ thed4rkestrose

Thoughts

UVa Problem Solution: 10009 - All Roads Lead Where?

Link: http://uva.onlinejudge.org/external/100/10009.pdf
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>

#define TOTAL_NODE 100
#define INVALID 2147483647


typedef struct mNode{
    int iNodeName;
    int iEdgeWeight;
    bool rVisited;
    int rCost;
    struct mNode *iNextNode;
    struct mNode *rPreviousNode;
    struct mNode *bBaseAddress;

}Node;

Node *AllNodeList;
void PutInNodeList(int FromNode, int ToNode, int EdgeWeight);
Node * GetNodeBaseAddress(int NodeName);
int GetNodeDegree(int NodeName);
int NodeIndexHead = 0;
void SetupNode(Node *mNodeAddress, int mNodeName, int mEdgeWeight, int mCost, Node *mNodeBaseAddress);
int TotalNodeInGraph(void);
int TotalEdgeInGraph(void);
void UpdateNodeValues(Node *mNodeAddress, int mEdgeWeight, Node *mNextNode, int mCost, Node *mPreviousNode, int mVisited);
void ClearGRAPH();

void Enqueue(Node *,Node *);
bool Dequeue(Node **,Node **);
void InitializeQueue();
int BFS(int startNode,int endNode,int startCost);
void ClearBFSResult();

char NameList;
void CreateNodeNameList(char *);
int StringtoNodeName(char *);
void ClearNameList(void);

int main()
{
    freopen("input.txt","r",stdin);
    Node *tmpNode;
    int caseCount,i,j,k,mQuery,mEdges,f,s,mR;
    scanf("%d\n",&caseCount);
    char cityName,city1,city2,mResult;
    for(i=0;i<caseCount;i++){
        scanf("%d%d\n",&mEdges,&mQuery);
        for(j=0;j<mEdges;j++){
            gets(cityName);
            sscanf(cityName,"%s%s",city1,city2);
            f=city1[0];
            s=city2[0];
            PutInNodeList(f,s,1);
            PutInNodeList(s,f,1);

        }

        for(j=0;j<mQuery;j++){
            gets(cityName);
            sscanf(cityName,"%s%s",city1,city2);
            f=city1[0];
            s=city2[0];
            if(BFS(f,s,0)){
                tmpNode = GetNodeBaseAddress(s);
                mR=0;
                while(tmpNode != NULL){
                    mResult=tmpNode->iNodeName;
                    tmpNode = tmpNode->rPreviousNode;
                }
                for(k=mR-1;k>=0;k--){
                    putchar(mResult[k]);
                }
                putchar('\n');
            }else{
                printf("%c%c\n",f,s);
            }
            ClearBFSResult();
        }
        if(i+1<caseCount) putchar('\n');
        ClearGRAPH();
        scanf("\n");

    }


    return 0;
}

typedef struct smQueue{
    Node *smX;
    Node *smY;
    struct smQueue *next;
}smNode;


smNode *smFirstNode, *smLastNode, *tempNode;
bool firstTime = true;

void Enqueue(Node *valX, Node *valY){
    smNode *nde = malloc(1 * sizeof(smNode));
    if(firstTime){
        firstTime = false;
        smFirstNode = nde;
        smLastNode = nde;
        smLastNode->smX = valX;
        smLastNode->smY = valY;
        smLastNode->next = NULL;
        return;
    }
    smLastNode->next = nde;
    smLastNode = nde;
    smLastNode->smX = valX;
    smLastNode->smY = valY;
    smLastNode->next = NULL;

}


bool Dequeue(Node **smValueX, Node **smValueY){

    if(smFirstNode!=NULL){
        *smValueX = smFirstNode->smX;
        *smValueY = smFirstNode->smY;
        tempNode = smFirstNode->next;
        free(smFirstNode);
        smFirstNode = tempNode;
        if(smFirstNode==NULL){
            firstTime = true;
        }
        return true;
    }
    return false;
}

void InitializeQueue(){
    Node *a,*b;
    while(Dequeue(&a,&b));
}



void PutInNodeList(int FromNode, int ToNode, int EdgeWeight){
    Node *tempNode = GetNodeBaseAddress(FromNode);

    if(tempNode != NULL){
        while(tempNode->iNextNode != NULL){
            tempNode = tempNode->iNextNode;
        }
        Node *tmp = (Node*) malloc(1 * sizeof(Node));

        Node *baseAddress = GetNodeBaseAddress(ToNode);
        if(baseAddress == NULL){
            baseAddress = (Node*) malloc(1 * sizeof(Node));
            SetupNode(baseAddress,ToNode,INVALID,INVALID,baseAddress);
            AllNodeList = baseAddress;
        }

        SetupNode(tmp,ToNode,EdgeWeight,INVALID,baseAddress);
        tempNode->iNextNode = tmp;

    }else{
        Node *tmp1 = (Node*) malloc(1 * sizeof(Node));
        SetupNode(tmp1,FromNode,INVALID,INVALID,tmp1);
        AllNodeList = tmp1;
        int tmpNodeHead = NodeIndexHead-1;

        Node *baseAddress = GetNodeBaseAddress(ToNode);
        if(baseAddress == NULL){
            baseAddress = (Node*) malloc(1 * sizeof(Node));
            SetupNode(baseAddress,ToNode,INVALID,INVALID,baseAddress);
            AllNodeList = baseAddress;
        }

        Node *tmp2 = (Node*) malloc(1 * sizeof(Node));
        SetupNode(tmp2,ToNode,EdgeWeight,INVALID,baseAddress);
        AllNodeList -> iNextNode = tmp2;
    }
}

void SetupNode(Node *mNodeAddress, int mNodeName, int mEdgeWeight, int mCost, Node *mNodeBaseAddress){
    mNodeAddress->iEdgeWeight = mEdgeWeight;
    mNodeAddress->iNextNode = NULL;
    mNodeAddress->iNodeName = mNodeName;
    mNodeAddress->rCost = mCost;
    mNodeAddress->rPreviousNode = NULL;
    mNodeAddress->rVisited = false;
    mNodeAddress->bBaseAddress = mNodeBaseAddress;
}

void UpdateNodeValues(Node *mNodeAddress,
                      int mEdgeWeight,
                      Node *mNextNode,
                      int mCost,
                      Node *mPreviousNode,
                      int mVisited){
    if(mEdgeWeight!=INVALID){
        mNodeAddress->iEdgeWeight=mEdgeWeight;
    }

    if(mNextNode != NULL){
        mNodeAddress->iNextNode = mNextNode;
    }

    if(mCost != INVALID){
        mNodeAddress->rCost = mCost;
    }

    if(mPreviousNode!=NULL){
        mNodeAddress->rPreviousNode=mPreviousNode;
    }
    if(mVisited != 0){
        if(mVisited>0){
            mNodeAddress->rVisited = true;
        }else{
            mNodeAddress->rVisited = false;
        }
    }

}


Node * GetNodeBaseAddress(int NodeName){
    int i;
    for(i=0;i<NodeIndexHead;i++){
        if(AllNodeList[i]->iNodeName == NodeName){
            return AllNodeList[i];
        }
    }
    return NULL;
}

int GetNodeDegree(int NodeName){
    Node* tmp = GetNodeBaseAddress(NodeName);
    int i=0;
    if(tmp!=NULL){
        tmp = tmp->iNextNode;
    }
    while(tmp!=NULL){
        i++;
        tmp=tmp->iNextNode;
    }
    return i;
}

int TotalNodeInGraph(){
    return NodeIndexHead;
}

int TotalEdgeInGraph(){
    return INVALID;
}

void ClearGRAPH(){
    int i;
    for(i=0;i<NodeIndexHead;i++){
        AllNodeList[i]=NULL;
    }
    NodeIndexHead = 0;
}

int BFS(int startNode,int endNode,int startCost){

    Node *bfsTmpNode, *bfsTmpParentNode, *bfsGarbageNode,*bfsListTraversal;

    bfsTmpNode = GetNodeBaseAddress(startNode);
    if(bfsTmpNode==NULL){
        return 0;
    }
    InitializeQueue();
    bfsTmpNode->rVisited = true;
    bfsTmpNode->rCost = startCost;
    bfsTmpNode->rPreviousNode = NULL;
    Enqueue(bfsTmpNode,NULL);

    while(Dequeue(&bfsTmpParentNode,&bfsGarbageNode)){
        bfsListTraversal = bfsTmpParentNode;

        while(1){
            bfsListTraversal = bfsListTraversal->iNextNode;
            if(bfsListTraversal==NULL) break;

            bfsTmpNode = bfsListTraversal->bBaseAddress;
            if(bfsTmpNode->rVisited) continue;
            bfsTmpNode->rVisited = true;
            bfsTmpNode->rCost = bfsTmpParentNode->rCost + 1;

            bfsTmpNode->rPreviousNode = bfsTmpParentNode;
            if(bfsTmpNode->iNodeName == endNode){
                return 1;
            }
            Enqueue(bfsTmpNode,NULL);
        }
    }

    return 0;
}

void ClearBFSResult(){
    int i;
    for(i=0;i<NodeIndexHead;i++){
        AllNodeList[i]->rCost = INVALID;
        AllNodeList[i]->rPreviousNode = NULL;
        AllNodeList[i]->rVisited = false;
    }

} 7 more words
UVa

UVa Problem Solution: 383 - Shipping Routes

Link: http://uva.onlinejudge.org/external/3/383.pdf

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>

#define TOTAL_NODE 100
#define INVALID 2147483647


typedef struct mNode{
    int iNodeName;
    int iEdgeWeight;
    bool rVisited;
    int rCost;
    struct mNode *iNextNode;
    struct mNode *rPreviousNode;
    struct mNode *bBaseAddress;

}Node;

Node *AllNodeList;
void PutInNodeList(int FromNode, int ToNode, int EdgeWeight);
Node * GetNodeBaseAddress(int NodeName);
int GetNodeDegree(int NodeName);
int NodeIndexHead = 0;
void SetupNode(Node *mNodeAddress, int mNodeName, int mEdgeWeight, int mCost, Node *mNodeBaseAddress);
int TotalNodeInGraph(void);
int TotalEdgeInGraph(void);
void UpdateNodeValues(Node *mNodeAddress, int mEdgeWeight, Node *mNextNode, int mCost, Node *mPreviousNode, int mVisited);
void ClearGRAPH();

void Enqueue(Node *,Node *);
bool Dequeue(Node **,Node **);
void InitializeQueue();
int BFS(int startNode,int endNode,int startCost);
void ClearBFSResult();

char NameList;
void CreateNodeNameList(char *);
int StringtoNodeName(char *);
void ClearNameList(void);



int main()
{
    freopen("input.txt","r",stdin);
    int caseCount, WareHouseCount, EdgeCount, OutputRequests,i,j,PacketSize,EdgeLength;
    char ttn1,ttn,ttn2;
    int f,s,TotalCost;
    scanf("%d\n",&caseCount);
    printf("SHIPPING ROUTES OUTPUT\n\n");
    for(i=0;i<caseCount;i++){
        printf("DATA SET  %d\n\n",i+1);
        scanf("%d%d%d\n",&WareHouseCount,&EdgeCount,&OutputRequests);
        for(j=0;j<WareHouseCount;j++){
            scanf("%s",ttn1);
            CreateNodeNameList(ttn1);
        }
        scanf("\n");
        for(j=0;j<EdgeCount;j++){
            gets(ttn);
            sscanf(ttn,"%s%s",ttn1,ttn2);
            f=StringtoNodeName(ttn1);
            s=StringtoNodeName(ttn2);
            PutInNodeList(f,s,1);
            PutInNodeList(s,f,1);
        }

        for(j=0;j<OutputRequests;j++){
            gets(ttn);
            sscanf(ttn,"%d%s%s",&PacketSize,ttn1,ttn2);
            f=StringtoNodeName(ttn1);
            s=StringtoNodeName(ttn2);
            EdgeLength = BFS(f,s,0);
            TotalCost = EdgeLength * PacketSize * 100;
            if(EdgeLength != 0){
                printf("$%d\n",TotalCost);
            }else{
                printf("NO SHIPMENT POSSIBLE\n");
            }

            ClearBFSResult();
        }
        ClearGRAPH();
        ClearNameList();
        if(i+1<caseCount) putchar('\n');
    }
    printf("\nEND OF OUTPUT\n");

    return 0;
}

int b=0;
void CreateNodeNameList(char *name){

    strcpy(&NameList[0],name);

}

int StringtoNodeName(char *name){
    int p;
    for(p=0;p<b;p++){
        if(strcmp(name,&NameList[p][0]) == 0) return p;
    }

    return -1;
}

void ClearNameList(){
    b=0;
}


typedef struct smQueue{
    Node *smX;
    Node *smY;
    struct smQueue *next;
}smNode;


smNode *smFirstNode, *smLastNode, *tempNode;
bool firstTime = true;

void Enqueue(Node *valX, Node *valY){
    smNode *nde = malloc(1 * sizeof(smNode));
    if(firstTime){
        firstTime = false;
        smFirstNode = nde;
        smLastNode = nde;
        smLastNode->smX = valX;
        smLastNode->smY = valY;
        smLastNode->next = NULL;
        return;
    }
    smLastNode->next = nde;
    smLastNode = nde;
    smLastNode->smX = valX;
    smLastNode->smY = valY;
    smLastNode->next = NULL;

}


bool Dequeue(Node **smValueX, Node **smValueY){

    if(smFirstNode!=NULL){
        *smValueX = smFirstNode->smX;
        *smValueY = smFirstNode->smY;
        tempNode = smFirstNode->next;
        free(smFirstNode);
        smFirstNode = tempNode;
        if(smFirstNode==NULL){
            firstTime = true;
        }
        return true;
    }
    return false;
}

void InitializeQueue(){
    Node *a,*b;
    while(Dequeue(&a,&b));
}



void PutInNodeList(int FromNode, int ToNode, int EdgeWeight){
    Node *tempNode = GetNodeBaseAddress(FromNode);

    if(tempNode != NULL){
        while(tempNode->iNextNode != NULL){
            tempNode = tempNode->iNextNode;
        }
        Node *tmp = (Node*) malloc(1 * sizeof(Node));

        Node *baseAddress = GetNodeBaseAddress(ToNode);
        if(baseAddress == NULL){
            baseAddress = (Node*) malloc(1 * sizeof(Node));
            SetupNode(baseAddress,ToNode,INVALID,INVALID,baseAddress);
            AllNodeList = baseAddress;
        }

        SetupNode(tmp,ToNode,EdgeWeight,INVALID,baseAddress);
        tempNode->iNextNode = tmp;

    }else{
        Node *tmp1 = (Node*) malloc(1 * sizeof(Node));
        SetupNode(tmp1,FromNode,INVALID,INVALID,tmp1);
        AllNodeList = tmp1;
        int tmpNodeHead = NodeIndexHead-1;

        Node *baseAddress = GetNodeBaseAddress(ToNode);
        if(baseAddress == NULL){
            baseAddress = (Node*) malloc(1 * sizeof(Node));
            SetupNode(baseAddress,ToNode,INVALID,INVALID,baseAddress);
            AllNodeList = baseAddress;
        }

        Node *tmp2 = (Node*) malloc(1 * sizeof(Node));
        SetupNode(tmp2,ToNode,EdgeWeight,INVALID,baseAddress);
        AllNodeList -> iNextNode = tmp2;
    }
}

void SetupNode(Node *mNodeAddress, int mNodeName, int mEdgeWeight, int mCost, Node *mNodeBaseAddress){
    mNodeAddress->iEdgeWeight = mEdgeWeight;
    mNodeAddress->iNextNode = NULL;
    mNodeAddress->iNodeName = mNodeName;
    mNodeAddress->rCost = mCost;
    mNodeAddress->rPreviousNode = NULL;
    mNodeAddress->rVisited = false;
    mNodeAddress->bBaseAddress = mNodeBaseAddress;
}

void UpdateNodeValues(Node *mNodeAddress,
                      int mEdgeWeight,
                      Node *mNextNode,
                      int mCost,
                      Node *mPreviousNode,
                      int mVisited){
    if(mEdgeWeight!=INVALID){
        mNodeAddress->iEdgeWeight=mEdgeWeight;
    }

    if(mNextNode != NULL){
        mNodeAddress->iNextNode = mNextNode;
    }

    if(mCost != INVALID){
        mNodeAddress->rCost = mCost;
    }

    if(mPreviousNode!=NULL){
        mNodeAddress->rPreviousNode=mPreviousNode;
    }
    if(mVisited != 0){
        if(mVisited>0){
            mNodeAddress->rVisited = true;
        }else{
            mNodeAddress->rVisited = false;
        }
    }

}


Node * GetNodeBaseAddress(int NodeName){
    int i;
    for(i=0;i<NodeIndexHead;i++){
        if(AllNodeList[i]->iNodeName == NodeName){
            return AllNodeList[i];
        }
    }
    return NULL;
}

int GetNodeDegree(int NodeName){
    Node* tmp = GetNodeBaseAddress(NodeName);
    int i=0;
    if(tmp!=NULL){
        tmp = tmp->iNextNode;
    }
    while(tmp!=NULL){
        i++;
        tmp=tmp->iNextNode;
    }
    return i;
}

int TotalNodeInGraph(){
    return NodeIndexHead;
}

int TotalEdgeInGraph(){
    return INVALID;
}

void ClearGRAPH(){
    int i;
    for(i=0;i<NodeIndexHead;i++){
        AllNodeList[i]=NULL;
    }
    NodeIndexHead = 0;
}

int BFS(int startNode,int endNode,int startCost){

    Node *bfsTmpNode, *bfsTmpParentNode, *bfsGarbageNode,*bfsListTraversal;

    bfsTmpNode = GetNodeBaseAddress(startNode);
    if(bfsTmpNode==NULL){
        return 0;
    }
    InitializeQueue();
    bfsTmpNode->rVisited = true;
    bfsTmpNode->rCost = startCost;
    bfsTmpNode->rPreviousNode = NULL;
    Enqueue(bfsTmpNode,NULL);

    while(Dequeue(&bfsTmpParentNode,&bfsGarbageNode)){
        bfsListTraversal = bfsTmpParentNode;

        while(1){
            bfsListTraversal = bfsListTraversal->iNextNode;
            if(bfsListTraversal==NULL) break;

            bfsTmpNode = bfsListTraversal->bBaseAddress;
            if(bfsTmpNode->rVisited) continue;
            bfsTmpNode->rVisited = true;
            bfsTmpNode->rCost = bfsTmpParentNode->rCost + 1;

            bfsTmpNode->rPreviousNode = bfsTmpParentNode;
            if(bfsTmpNode->iNodeName == endNode){
                return bfsTmpNode->rCost;
            }
            Enqueue(bfsTmpNode,NULL);
        }
    }

    return 0;
}

void ClearBFSResult(){
    int i;
    for(i=0;i<NodeIndexHead;i++){
        AllNodeList[i]->rCost = INVALID;
        AllNodeList[i]->rPreviousNode = NULL;
        AllNodeList[i]->rVisited = false;
    }

} 7 more words
UVa