src/GraphCreation.c
/*
 * FUNCTION NAME: addNodeToAdjacencyList
 *
 * DESCRIPTION:
 * Calls the function that creates node. Then
 * adds a node as a head of the list.
 */
FUNCTION NAME: addNodeToAdjacencyList
DESCRIPTION:
Calls the function that creates node. Then
adds a node as a head of the list.
FUNCTION NAME : addNodeToAdjacencyList DESCRIPTION : Calls the function that creates node . Then adds a node as a head of the list .
void addNodeToAdjacencyList(AdjacencyList_t* adjacency_list, const char* to, double distance)
{
    AdjacencyListNode_t* node = makeAdjacencyListNode(to, distance);
    AdjacencyListNode_t* temp1;
    if (adjacency_list->head == NULL) { 
        adjacency_list->head = node;
    } else {
        if (adjacency_list->head->next == NULL) { 
            if (strcmp(to, adjacency_list->head->to) > 0) { 
                adjacency_list->head->next = node; 
            } else if (strcmp(to, adjacency_list->head->to) < 0) {
                node->next = adjacency_list->head;
                adjacency_list->head = node;
            }
        }
        else if (adjacency_list->head->next != NULL) {
            if (strcmp(to, adjacency_list->head->to) < 0) {
                node->next = adjacency_list->head;
                adjacency_list->head = node;
            }
            else {
                for (temp1 = adjacency_list->head; temp1 != NULL; temp1 = temp1->next) {
                    if (temp1->next != NULL && strcmp(to, temp1->to) > 0 && strcmp(to, temp1->next->to) < 0) {
                        node->next = temp1->next;
                        temp1->next = node;
                        break;
                    }
                    else if (temp1->next == NULL && strcmp(to, temp1->to) > 0) {
                        temp1->next = node;
                    }
                }
            }
        }
    }
}
void addNodeToAdjacencyList ( AdjacencyList_t * adjacency_list , const char * to , double distance ) { AdjacencyListNode_t * node = makeAdjacencyListNode ( to , distance ) ; AdjacencyListNode_t * temp1 ; if ( adjacency_list -> head == NULL ) { adjacency_list -> head = node ; } else { if ( adjacency_list -> head -> next == NULL ) { if ( strcmp ( to , adjacency_list -> head -> to ) > 0 ) { adjacency_list -> head -> next = node ; } else if ( strcmp ( to , adjacency_list -> head -> to ) < 0 ) { node -> next = adjacency_list -> head ; adjacency_list -> head = node ; } } else if ( adjacency_list -> head -> next != NULL ) { if ( strcmp ( to , adjacency_list -> head -> to ) < 0 ) { node -> next = adjacency_list -> head ; adjacency_list -> head = node ; } else { for ( temp1 = adjacency_list -> head ; temp1 != NULL ; temp1 = temp1 -> next ) { if ( temp1 -> next != NULL && strcmp ( to , temp1 -> to ) > 0 && strcmp ( to , temp1 -> next -> to ) < 0 ) { node -> next = temp1 -> next ; temp1 -> next = node ; break ; } else if ( temp1 -> next == NULL && strcmp ( to , temp1 -> to ) > 0 ) { temp1 -> next = node ; } } } } } }
FUNCTION NAME: addNodeToAdjacencyList
 DESCRIPTION:
 Calls the function that creates node.
FUNCTION NAME : addNodeToAdjacencyList DESCRIPTION : Calls the function that creates node .
/* If adjacency list is empty, then create head.
     * If it is not, then check two cases: if there is one element
     * in the list only or if there are more. */ /* Empty adjacency list. */ /* Adjacency list with only 1 element. */ /* Compare, if city that is about to be added should */ /* be before or after element that is already in the list. */ /* If there are more elements in the list, then search
             * where element should be added.
             * If previous element is lesser and next is greater (in alphabetical order)
             * then add a node here. */ /* If added element will be first in the list. */ /* If added element won't be first in the list. */ /* If added element will be in the middle of the list. */ /* If added element will be at the end of the list. */