bool LinkedList::search_requests(string &origin, string &destination, double &totalCost, Stack &flight_stack, ofstream &output) { double currentCost = 0.0; string dest_asOrigin; Node* origin_node = head; if(origin_node == NULL) //If there is no such origin city return false; while(origin_node != NULL) { if(origin == origin_node -> cityName) { Node* destination_node = origin_node; destination_node = destination_node -> next; while(destination_node != NULL) { currentCost = destination_node -> cost; dest_asOrigin = destination_node -> cityName; bool onStack = flight_stack.if_exists(dest_asOrigin); if(destination == destination_node -> cityName && onStack == false) //If destination is found { totalCost += destination_node -> cost; flight_stack.push(origin, dest_asOrigin, currentCost); return true; } else if(destination != destination_node -> cityName && onStack == false) { flight_stack.push(origin, dest_asOrigin, currentCost); bool found = search_requests(dest_asOrigin, destination, totalCost, flight_stack, output); if(found == true) { totalCost += destination_node -> cost; return true; } else if(found == false) { flight_stack.pop(); } } destination_node = destination_node -> next; } } origin_node = origin_node -> down; } return false; }
void friendrequest::on_pushButton_clicked() { ui->listWidget->clear(); emit search_requests(); }