コード例 #1
0
ファイル: main.cpp プロジェクト: chris-womack/dataStructures
void delete_node(string node, City *Head, int *op_count){

    City *Traverse;
    Traverse = Head;
    op_count++;
    op_count++;

    // search for Denver in Linked List
    while(Traverse->getPlace() != node and Traverse->getNext() != NULL){
        Traverse = Traverse->getNext();
        op_count++;
    }

    // Delete node Denver in LinkedList
    if(Traverse->getPlace() == node){
        Traverse->getPrev()->setNext(Traverse->getNext());
        Traverse->getNext()->setPrev(Traverse->getPrev());
        delete Traverse;
        op_count++;
        op_count++;
        op_count++;
    }
    op_count++;

    // Print Cities to show deletion of Denver
    Traverse = Head;
    while(Traverse->getNext() != NULL){
        Traverse = Traverse->getNext();
        cout << Traverse->getPlace() << endl;
        op_count++;
        op_count++;
    }
    cout << endl;
}
コード例 #2
0
ファイル: main.cpp プロジェクト: chris-womack/dataStructures
void add_node(City *Head, int *op_count){

    string new_city, prev_city;
    cout << "Input the new city to add to network as well as the city that should precede it seperated by a space." << endl;
    cin >> new_city;
    cin >> prev_city;
    cout << endl;

    City *Traverse;
    Traverse = Head;
    op_count++;
    op_count++;

    while(Traverse->getPlace() != prev_city and Traverse->getNext() != NULL){
        Traverse = Traverse->getNext();
        op_count++;
    }

    // add the new city to the grid
    if(Traverse->getPlace() == prev_city){

        City *NewCity = new City("NULL","NULL");

        if(prev_city == "Boston"){
            NewCity->setPlace(new_city);
            NewCity->setPrev(Traverse->getPrev()->getNext());
            Traverse->setNext(NewCity);
            op_count++;
            op_count++;
            op_count++;

        }else{
            NewCity->setPlace(new_city);
            NewCity->setNext(Traverse->getNext());
            NewCity->setPrev(Traverse->getNext()->getPrev());
            Traverse->getNext()->setPrev(NewCity);
            Traverse->setNext(NewCity);
            op_count++;
            op_count++;
            op_count++;
            op_count++;
            op_count++;

        }
        op_count++;
    }
    op_count++;

    // Print Cities to show Addition of New City
    Traverse = Head;
    while(Traverse->getNext() != NULL){
        Traverse = Traverse->getNext();
        cout << Traverse->getPlace() << endl;
        //cout << Traverse->getNext() << endl;
        op_count++;
        op_count++;
    }
    cout << endl;;
}