Home > OS >  This assignment is designed to explore linked lists so you will implement a singly linked-list to ho
This assignment is designed to explore linked lists so you will implement a singly linked-list to ho

Time:05-20

I need help please It keeps giving me the same number and not a different one.

Bid LinkedList::Search(string bidId) {
    // FIXME (6): Implement search logic

    // special case if matching node is the head
        // make head point to the next node in the list
        //decrease size count
        //return

    // start at the head of the list

    // keep searching until end reached with while loop (next != nullptr
        // if the current node matches, return it
        // else current node is equal to next node

     //return bid
    Node* temp = head;
    Node* holder = new Node;
    holder->bid.bidId = "";
    while (temp != nullptr) {
        cout << temp->bid.bidId << endl;
        if (temp->bid.bidId == bidId) {
            return temp->bid;
        }
        temp = temp->next;
        return holder->bid;
    }
}

CodePudding user response:

Just remove everything with a holder. And at the end throw an exception when nothing was found. Alternatively return std::optional<Bid>.

  • Related