int main(int argc, char** argv) {
    //freopen("Trojan.txt", "r", stdin);
    LinkedList<int> List;
    List.Add(1);
    List.Add(3);
    List.Add(5);
    List.Add(7);
    List.Traverse(); // Output : 1 .. 3 .. 5 .. 7 .. END
    List.Reverse(); 
    List.Traverse(); // Output : 7 .. 5 .. 3  .. 1 .. END
    List.Delete(5);
    List.Traverse(); // Output : 7  .. 3 .. 1 .. END

    return 0;
}
示例#2
0
int main()
{
	LinkedList<int> List;

	for (int i = 0; i < 100000; i++)
		List.Add(i);

	int test = List[0];

	for (int i = 0; i < 10000; i++)
	std::cout << List[i];	

	std::cin.get();
	return 0;
}
示例#3
0
int main()
{
	//Allowed characters in a 
	std::string valid = "abcdefghijklmnopqrstuvwxyz";

	std::locale loc; 
	Hashing* hash = new Hashing();
	LinkedList* misspelled = new LinkedList(); 
	//std::ifstream dictionary("D:\\DataStructures\\Hashing\\Hashing\\Hashing\\dictionary.txt");// laptop
	std::ifstream dictionary("J:\\Data Structures\\Hashing\\Hashing\\Hashing\\dictionary.txt"); //desktop 
	std::string line; 
	
	while (std::getline(dictionary, line))
	{
		for (std::string::size_type i = 0; i < line.length(); ++i)
		{
			std::tolower(line[i], loc); 
		}
		hash->Insert(line);
	}
	
	dictionary.close(); 

	std::ifstream _mispelled("J:\\Data Structures\\Hashing\\Hashing\\Hashing\\mispelled.txt");
	std::string str; 

	std::getline(_mispelled, str);
	
	std::string buffer;
	std::stringstream ss(str); 
	
	char comma = ',';
	char period = '.';
	char quotes = '"';
	char left = '(';
	char right = ')'; 
	
	while (ss >> buffer)
	{
		for (std::string::iterator it = buffer.begin(); it != buffer.end();)
		{
			if ((*it) == comma || (*it) == period || (*it) == quotes || (*it) == left || (*it) == right)
			{
				it = buffer.erase(it);
			}
			else
			{
				it++;
			}
		}

		std::size_t found = buffer.find_first_not_of(valid);
		if (found != std::string::npos)
		{
			continue;
		}
			misspelled->Add(buffer);
		}
	
	std::cout << "Mispelled Words" << std::endl; 
	std::cout << "================================" << std::endl; 

	for (int i = 0; i < misspelled->GetLength(); ++i)
	{
		std::string temp = hash->CheckForValue(misspelled->GetValueAtPosition(i)); 
		if (temp != "")
		{
			std::cout << temp << std::endl; 
		}
	}
	hash->CheckForValue("spell");
	hash->Histogram(); 
	system("PAUSE");
}
示例#4
0
void HoldemRules::DetermineWinners()
{
    //--------------------------------------------
    // Calculate best combinations for all players
    //Debug("DetermineWinners 1");
    const LinkedList<Card*>& r_comm_cards = mrTable.GetCommunityCards();
    //Debug("DetermineWinners 2");
    LinkedList<Player*>& players = mrTable.GetPlayers();
    //Debug("DetermineWinners 3");
    for (LinkedList<Player*>::Iterator i = players.Begin(); !i.Done(); i++) {
        if ((*i)->IsFolded()) {
    	    Debug(String("Player [") + (*i)->Name() + "] is folded");
            continue;
        }
        Debug(String("DetermineWinners 4: [") + (*i)->Name() + "]");
        const LinkedList<Card*>& r_player_cards = (*i)->GetCards();
        Debug("DetermineWinners 5");
        Card* cards[r_player_cards.Size() + r_comm_cards.Size()];
        Debug("DetermineWinners 6");
        //cout << "--------------------------------------\n";
        cout << '[' << (*i)->Name() << "] shows: ";
        int j;
        for (j = 0; j < r_player_cards.Size(); j++) {
            cards[j] = r_player_cards[j];
            Debug(r_player_cards[j]->ToString() + " ");
            cout << r_player_cards[j]->ToString() << ' ';
        }
        cout << '\n';
        Debug("--");
        for (j = r_player_cards.Size(); j < r_player_cards.Size() + r_comm_cards.Size(); j++) {
            cards[j] = r_comm_cards[j - r_player_cards.Size()];
            Debug(r_comm_cards[j - r_player_cards.Size()]->ToString() + " ");
        }
        Debug("\n");
        Debug("DetermineWinners 8");
	    (*i)->SetHandStrength(GetHandStrength(cards, r_player_cards.Size() + r_comm_cards.Size()));
	    Debug(String("Hand strength for [") + (*i)->Name() + "]: " + (long) (*i)->HandStrength());
        Debug("DetermineWinners 9");
    }
    
    //-------------------------------
    // Order players by hand strength
    
    LinkedList<LinkedList<Player*>* > winners;
    Debug("DetermineWinners 10");
    
    int num_winners = 0;
    for (;;) {
    //while (num_winners < players.Size()) {
        Debug("DetermineWinners 11");
        unsigned long max_strength = 0;
        for (LinkedList<Player*>::Iterator i = players.Begin(); !i.Done(); i++) {
            if ((*i)->IsFolded()) {
                continue;
            }
            if ((*i)->HandStrength() > max_strength) {
                max_strength = (*i)->HandStrength();
            }
        }
        if (max_strength <= 0) {
            Debug(String("DetermineWinners: Thats all"));
            // No more winners
            break;
        }
        Debug(String("DetermineWinners: max_strength = ") + (long) max_strength);
        LinkedList<Player*>* p_w = new LinkedList<Player*>();

        for (LinkedList<Player*>::Iterator i = players.Begin(); !i.Done(); i++) {
            if ((*i)->IsFolded()) {
                continue;
            }
            if ((*i)->HandStrength() == max_strength) {
                p_w->Add((*i));
                (*i)->SetHandStrength(0);
                num_winners++;
                Debug(String("DetermineWinners: adding winner: [") + (*i)->Name() + "]");
            }
        }
        Debug("DetermineWinners 111");
        if (p_w->Size() > 0) {
            Debug("DetermineWinners 1111");
            winners.Add(p_w);
            Debug("DetermineWinners 11111");
        }
    }

    Debug("DetermineWinners 12");
    //-----------------------------------------------------    
    // Iterate ower winners and add wins to player balances
    
    for (LinkedList<LinkedList<Player*>* >::Iterator i = winners.Begin(); !i.Done(); i++) {
        mrTable.GetPotManager().Win(*(*i));
        delete (*i);
    }
    winners.Clear();
}
示例#5
0
//-----------------------------------------------------------------------------
// Builds an occlusion volume for the given occluder.
//-----------------------------------------------------------------------------
void SceneManager::BuildOcclusionVolume( SceneOccluder *occluder, D3DXVECTOR3 viewer )
{
	// Create a list of edges for the occluder's silhouette.
	LinkedList< Edge > *edges = new LinkedList< Edge >;

	// Go through all the faces in the occluder's mesh.
	for( unsigned long f = 0; f < occluder->totalFaces; f++ )
	{
		// Get the indices of this face.
		unsigned short index0 = occluder->indices[3 * f + 0];
		unsigned short index1 = occluder->indices[3 * f + 1];
		unsigned short index2 = occluder->indices[3 * f + 2];

		// Find the angle between the face's normal and the vector point from
		// viewer's position to the face's position. If the angle is less than
		// 0, then the face is visible to the viewer.
		if( D3DXVec3Dot( &occluder->vertices[index0].normal, &( occluder->vertices[index0].translation - viewer ) ) < 0.0f )
		{
			// Check if the list of edges is empty.
			if( edges->GetTotalElements() == 0 )
			{
				// Add all the edges for this face.
				edges->Add( new Edge( &occluder->vertices[index0], &occluder->vertices[index1] ) );
				edges->Add( new Edge( &occluder->vertices[index1], &occluder->vertices[index2] ) );
				edges->Add( new Edge( &occluder->vertices[index2], &occluder->vertices[index0] ) );
			}
			else
			{
				Edge *found0 = NULL;
				Edge *found1 = NULL;
				Edge *found2 = NULL;

				// Iterate through the list of edges.
				edges->Iterate( true );
				while( edges->Iterate() != NULL )
				{
					// Check if the first edge of this face already exists.
					if( ( edges->GetCurrent()->vertex0->translation == occluder->vertices[index0].translation && edges->GetCurrent()->vertex1->translation == occluder->vertices[index1].translation ) ||
						( edges->GetCurrent()->vertex0->translation == occluder->vertices[index1].translation && edges->GetCurrent()->vertex1->translation == occluder->vertices[index0].translation ) )
						found0 = edges->GetCurrent();

					// Check if the second edge of this face already exists.
					if( ( edges->GetCurrent()->vertex0->translation == occluder->vertices[index1].translation && edges->GetCurrent()->vertex1->translation == occluder->vertices[index2].translation ) ||
						( edges->GetCurrent()->vertex0->translation == occluder->vertices[index2].translation && edges->GetCurrent()->vertex1->translation == occluder->vertices[index1].translation ) )
						found1 = edges->GetCurrent();

					// Check if the third edge of this face already exists.
					if( ( edges->GetCurrent()->vertex0->translation == occluder->vertices[index2].translation && edges->GetCurrent()->vertex1->translation == occluder->vertices[index0].translation ) ||
						( edges->GetCurrent()->vertex0->translation == occluder->vertices[index0].translation && edges->GetCurrent()->vertex1->translation == occluder->vertices[index2].translation ) )
						found2 = edges->GetCurrent();
				}

				// If the first edge was found, remove it. Otherwise add it.
				if( found0 != NULL )
					edges->Remove( &found0 );
				else
					edges->Add( new Edge( &occluder->vertices[index0], &occluder->vertices[index1] ) );

				// If the second edge was found, remove it. Otherwise add it.
				if( found1 != NULL )
					edges->Remove( &found1 );
				else
					edges->Add( new Edge( &occluder->vertices[index1], &occluder->vertices[index2] ) );

				// If the thrid edge was found, remove it. Otherwise add it.
				if( found2 != NULL )
					edges->Remove( &found2 );
				else
					edges->Add( new Edge( &occluder->vertices[index2], &occluder->vertices[index0] ) );
			}
		}
	}

	// Empty the occluder's list of planes.
	occluder->planes->Empty();

	// Create the front cap plane.
	D3DXPLANE *plane = new D3DXPLANE;
	D3DXPlaneFromPointNormal( plane, &occluder->translation, &( occluder->translation - viewer ) );
	occluder->planes->Add( plane );

	// Iterate through the list of edges.
	edges->Iterate( true );
	while( edges->Iterate() != NULL )
	{
		// Get the position of the vertices in the edge.
		D3DXVECTOR3 vertex1 = edges->GetCurrent()->vertex0->translation;
		D3DXVECTOR3 vertex2 = edges->GetCurrent()->vertex1->translation;

		// Calculate the position of the thrid vertex for creating the plane.
		D3DXVECTOR3 dir = vertex1 - viewer;
		D3DXVec3Normalize( &dir, &dir );
		D3DXVECTOR3 vertex3 = vertex1 + dir;

		// Create a plane from this edge.
		plane = new D3DXPLANE;
		D3DXPlaneFromPoints( plane, &vertex1, &vertex2, &vertex3 );
		occluder->planes->Add( plane );
	}

	// Destroy the list of edges.
	SAFE_DELETE( edges );
}