Beispiel #1
0
void removeById(HashedDictionary<string, Racer>* dict, BinarySearchTree<Racer>* tree, Stack<Racer> *actionList, Stack<char> *commandList)
{
	ListNode<string, Racer>* nodePtr;
	string searchString;
	cout << "Please enter ID for deletion (8 chars) : ";
	getline(cin, searchString);
	if (searchString.length() > 8)
	{
		cout << "ID NUMBERS ARE 8 CHAR MAX!\n";
		return;
	}
	else if(!isId(searchString))
	{
		cout << "THIS IS NOT A VALID ID NUMBER!\n";
		return;
	}
	nodePtr = dict->getItem(searchString);
	if (nodePtr)
	{
		cout << "RACER FOUND!\n";
		display(nodePtr->getValue());
		string userInput = " ";
		cout << "ARE YOU SURE YOU WANT TO DELETE? (Y/n): ";
		getline(cin, userInput);
		if (userInput[0] == 'Y')
		{
			Racer toStack = nodePtr->getValue();
			actionList->push(toStack);
			commandList->push('-');
			dict->remove(searchString);
			tree->remove(nodePtr->getValue());
		}
		else
		{
			return;
		}	
	}
	else
	{
		cout << "NO RACER FOUND WITH THAT ID.\n";
	}
	
}
Beispiel #2
0
ostream & operator<<(ostream & stream, const LinkedList & list )
{
    ListNode* currNode = list.head;

    while (currNode != NULL)
    {
        cout << currNode->getValue();
        currNode = currNode->getNext();
    }
    
    return stream;
}
Beispiel #3
0
ListNode *LinkedList::search(const string &value)
{
    ListNode* currNode = head;

    if (head == NULL) return NULL;

    while (currNode != NULL)
    {
        if (currNode->getValue() == value)
            return currNode;

        currNode = currNode->getNext();
    }
}
Beispiel #4
0
ostream& operator<<(ostream &stream, const LinkedList &l) {
    
    stream << "[";
    
    ListNode *i = l.head;
    while(i != NULL) {
        stream << i->getValue();
        i = i->getNext();
        if(i != NULL)
            stream << ", ";
    }
    
    stream << "]";
    
}
Beispiel #5
0
void undo(Stack<Racer> *actionList, Stack<char> *commandList, HashedDictionary<string, Racer>* dict, BinarySearchTree<Racer>* tree)
{
    char command;
	Racer undoMe;
	if (commandList->getCount() != actionList->getCount() || commandList->isEmpty() || actionList->isEmpty())
	{
		cout << "No previous commands\n";
		return;
	}
	commandList->pop(command);
	actionList->pop(undoMe);
	string ID = *(undoMe.getIdNum());
	if (command == '+')
	{
		//string ID = *(undoMe.getIdNum());
		//remove from hashLL
		//dict->remove(ID);

		//remove from tree
		ListNode<string, Racer>* nodePtr;
		string searchString = ID;
		nodePtr = dict->getItem(searchString);
		if (nodePtr)
		{
			dict->remove(searchString);
			tree->remove(nodePtr->getValue());
			cout << "INSERT RETRACTED\n";
		}
	}
	if (command == '-')
	{
		dict->add(ID, undoMe);
		tree->insert(undoMe);
		cout << "DELETION RETRACTED\n\n";
		cout << "RESTORED DRIVER -> ";
		display(dict->getItem(ID)->getValue());
		cout << endl;
		
	}

}
Beispiel #6
0
void searchById(HashedDictionary<string, Racer>* dict)
{
	ListNode<string, Racer>* nodePtr;
	string searchString;
	cout << "Please enter the ID number that you are searching for(8 char max).\n"; 
	getline(cin, searchString);
	if(searchString.length() > 8)
	{
		cout << "ID NUMBERS ARE 8 CHAR MAX!\n";
		return;
	}
	nodePtr = dict->getItem(searchString);
	if(nodePtr)
	{
		cout << "RACER FOUND!\n";
		display(nodePtr->getValue());
	}
	else
		cout << "NO RACER FOUND WITH THAT ID.\n";

}
Beispiel #7
0
void LinkedList::remove(const string &value)
{
    ListNode* currNode = head;
    ListNode* prevNode;

    if (head == NULL) return;

    while (currNode != NULL)
    {
        if (currNode->getValue() == value)
        {
            if (prevNode != NULL)
                prevNode->next = currNode->getNext();
            else
                head = currNode->getNext();

            delete currNode;
        }
        prevNode = currNode;
        currNode = currNode->getNext();
    }
    last = currNode;
}